PHP DOM Xpath


php xpath

php dom xpath makes it very each to find and select elements / nodes in an xml document

select nodes

assuming that $doc contains a PHP DOMDocument you can use xpath to remove all nodes at any level that have the name "Name" with the following code

$xp = new DOMXPath($doc);

$nodes = $xp->query('//Name');

foreach($nodes as $n) { 
  $n->parentNode->removeChild($n);
}


review

you may want to add this before and after the transformation so you can see what has happened !

echo $doc->saveXML().PHP_EOL;


select nodes by attribute

or select all nodes that have the attribute 'editable' with the value 'false'

$nodes = $xp->query("//*[@editable='false']");



REFERRERS
PhpXml
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki