Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Functions to add / remove nodes to / from an XML file using PHP. (See related posts)

// description of your code here

<?php
function removNode($myXML, $node, $attribute, $id) {
    $xmlDoc = new DOMDocument();
    $xmlDoc->load($myXML);
    $xpath = new DOMXpath($xmlDoc);
   
    if( $attribute!='' || $id!='' )
    $nodeList = $xpath->query('//'.$node.'[@'.$attribute.'="'.$id.'"]');
    else
    $nodeList = $xpath->query('//'.$node.'');
   
    if ($nodeList->length)
    {
        $node = $nodeList->item(0)  ;
        $node->parentNode->removeChild($node);
    }
    $xmlDoc->save($myXML) ;
}   
?>

Management Games

You need to create an account or log in to post comments to this site.


Click here to browse all 7718 code snippets

Related Posts