note 43630 added to function.dom-domnode-replacechild
| From: | d-wetzelatgmxdotnet at rn2 dot php dot net | Date: | Mon, 28 Jun 2004 16:52:29 +0000 |
| Subject: | note 43630 added to function.dom-domnode-replacechild | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-72061@lists.php.net to get a copy of this message | ||
Hi folks,
for me it was really difficult to get this method working. But after a long search, I found that
solution. Please note: this is only a simple example - so be aware that you might have to make some
changes.
This is the xml-structure for the example (name it rChild.xml):
<?xml version="1.0"?>
<foo><bar><text>This is a
test.</text><text>Hello.</text></bar></foo>
And this is the code:
<?php
$document = new DomDocument();
$document->preserveWhiteSpace = false;
$document->load("rChild.xml");
$xpath = new domXPath($document);
$xpathQuery = $xpath->query("/foo/bar/text[position()=1]");
foreach ($xpathQuery as $nodeList)
{
$newText = $document->createTextNode("DOM in PHP5 is good.");
$nodeList->replaceChild($newText, $nodeList->firstChild);
$document->save("rChild.xml");
}
echo "<pre>" . htmlentities($document->saveXML()) . "</pre>";
?>
I hope that this could help you to understand this method.
Dominikus Wetzel
----
Manual Page -- http://www.php.net/manual/en/function.dom-domnode-replacechild.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+43630
Delete -- http://master.php.net/manage/user-notes.php?action=delete+43630&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+43630&report=yes
Search -- http://master.php.net/manage/user-notes.php