note 55950 added to function.dom-domnode-insertbefore

From: Date: Thu, 18 Aug 2005 19:18:59 +0000
Subject: note 55950 added to function.dom-domnode-insertbefore
Groups: php.notes 
Request: Send a blank email to php-notes+get-93852@lists.php.net to get a copy of this message
example to insert <newnode/> between <chid1/> and <child2/> <?xml version="1.0" encoding="ISO-8859-1" ?> <root> <parent> <child nr="1"/> <child nr="2"/> </parent> </root> <?php $xml_src = 'test.xml'; // XPath-Querys $parent_path = "//parent"; $next_path = "//parent/child[@nr='2']"; // Create a new DOM document $dom = new DomDocument(); $dom->load($xml_src); // Find the parent node $xpath = new DomXPath($dom); // Find parent node $parent = $xpath->query($parent_path); // new node will be inserted before this node $next = $xpath->query($next_path); // Create the new element $element = $dom->createElement('newnode'); // Insert the new element $parent->item(0)->insertBefore($element, $next->item(0)); echo $dom->saveXML(); ?> ---- Manual Page -- http://www.php.net/manual/en/function.dom-domnode-insertbefore.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+55950 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55950&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55950&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55950&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55950&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55950&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55950&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+55950&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#93852) next »