note 45378 deleted from function.dom-domnode-replacechild by aidan

From: Date: Fri, 24 Dec 2004 09:16:44 +0000
Subject: note 45378 deleted from function.dom-domnode-replacechild by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-82234@lists.php.net to get a copy of this message
Note Submitter: franp at free dot fr ---- If your XPath query returns a NodeList including a unique item, or if you know for sure the order of the items returned, you can use the "item(n)" syntax instead of the "foreach" syntax. This can greatly improve you code lisibility. As the method name implies, replaceChild cannot replace a node itself but a child of a node. The trick is to use replaceChild on the parent node of your Xpath query result. <?xml version="1.0" ?> <action> <actionGlobal> <actionGlobalFR>sometext</actionGlobalFR> <actionGlobal> </action> $frag = $doc->createElement("actionGlobalFR"); $fragA = $doc->createTextNode("anothertext"); $frag->appendChild($fragA); $xpResult = $xp->query("/action/actionGlobal/actionGlobalFR"); $blipblip = $xpResult->item(0)->parentNode->replaceChild($ajout, $xpResult->item(0)); Et voilà ! Note that the description of replaceChild in the doc is wrong. The correct description is : object DOMNode->replaceChild (object newnode, object oldnode)

« previous php.notes (#82234) next »