note 43630 deleted from function.dom-domnode-replacechild by didou
| From: | didou@php.net | Date: | Sat, 02 Apr 2005 22:43:49 +0000 |
| Subject: | note 43630 deleted from function.dom-domnode-replacechild by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-87376@lists.php.net to get a copy of this message | ||
Note Submitter: d-wetzel at gmx dot net
----
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