hey all, i just want to know why i can't replace a node into an xml tree. here's my code which drives me crazy.
note: i've never used the dom extension ever. is there any hidden information? why the php manual is so confusing on this?
I also tried the insertBefore() and replaceChild() method but none of them seem to work.Code:$q = "<component><name>test</name><some_element>this is the content</some_element></component>"; //New Dom Document $dom = new DOMDocument(); $dom->loadXML($xml); //new xpath for the query $xp = new DOMXPath($dom); foreach ($xp->query("//component[name='test']") as $node){ //Load XML into a new DOM Document object $rp = DOMDocument::loadXML($q); for( $child = $rp->documentElement->firstChild; $child; $child = $child->nextSibling ) $node->parentNode->replaceChild( $dom->importNode( $child ), $node); }
Thanks in advance,
Fotis




Bookmarks