note 56171 added to function.dom-domnode-insertbefore

From: Date: Thu, 25 Aug 2005 18:34:21 +0000
Subject: note 56171 added to function.dom-domnode-insertbefore
Groups: php.notes 
Request: Send a blank email to php-notes+get-94193@lists.php.net to get a copy of this message
moving an existing node within the DomDocument: <root> <parent> <child><name>Bob</name></child> <child><name>Sue</name></child> </parent> </root> $dom = new DomDocument(); $dom->load("sample.xml"); $parent_path = "/root"; $query = "//child[position() = 2]"; $query2 = "//child[position() = 1]"; $xpath = new DomXPath($dom); $parent = $xpath->query($parent_path); $under = $xpath->query($query); $above = $xpath->query($query2); $parent->item(0)->insertBefore($under->item(0), $above->item(0)); $dom->save("sample.xml"); Should produce: <root> <parent> <child><name>Sue</name></child> <child><name>Bob</name></child> </parent> </root> ---- Manual Page -- http://www.php.net/manual/en/function.dom-domnode-insertbefore.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+56171 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56171&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56171&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56171&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56171&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56171&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56171&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+56171&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#94193) next »