note 86773 modified in function.domnode-unlink-node by danbrown

From: Date: Mon, 03 Nov 2008 14:54:34 +0000
Subject: note 86773 modified in function.domnode-unlink-node by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-146087@lists.php.net to get a copy of this message
<?xml version="1.0"?> <galleries> <gallery title="test" intro=""> <image/> <image/> </gallery> <gallery title="test1" intro=""> <image/> <image/> <image/> <image/> </gallery> <gallery title="test2" intro=""> <image/> <image/> <image/> <image/> </gallery> </galleries> <?php $dom = domxml_open_file($xmlfilename, DOMXML_LOAD_DONT_KEEP_BLANKS) $x = $dom->get_elements_by_tagname('youtagname'); for($i=0;$i<count($x);$i++) { // to remove a particular node by finding the if($x[$i]->get_attribute('title')=="test1") { $remnode = $x[$i]->node_name(); $x[$i]->unlink_node($remnode); $dom->dump_file($xmlfilename, false, true); } } // Final xml will be like this: ?> <?xml version="1.0"?> <galleries> <gallery title="test" intro=""> <image/> <image/> </gallery> <gallery title="test2" intro=""> <image/> <image/> <image/> <image/> </gallery> </galleries> Njoi :) --was-- <?xml version="1.0"?> <galleries> <gallery title="test" intro=""> <image/> <image/> </gallery> <gallery title="test1" intro=""> <image/> <image/> <image/> <image/> </gallery> <gallery title="test2" intro=""> <image/> <image/> <image/> <image/> </gallery> </galleries> $dom = domxml_open_file($xmlfilename, DOMXML_LOAD_DONT_KEEP_BLANKS) $x = $dom->get_elements_by_tagname('youtagname'); for($i=0;$i<count($x);$i++) { // to remove a particular node by finding the if($x[$i]->get_attribute('title')=="test1") { $remnode = $x[$i]->node_name(); $x[$i]->unlink_node($remnode); $dom->dump_file($xmlfilename, false, true); } } final xml will be like this <?xml version="1.0"?> <galleries> <gallery title="test" intro=""> <image/> <image/> </gallery> <gallery title="test2" intro=""> <image/> <image/> <image/> <image/> </gallery> </galleries> Njoi :) http://php.net/manual/en/function.domnode-unlink-node.php

« previous php.notes (#146087) next »