src/Lib/XmlTool.php
public static function deleteElementsByXpath($node, $xpath_query, $namespaces = array())
    {
        if(is_a($node, 'DOMDocument'))
        {
            $xpath = new DOMXPath($node);
        }
        elseif(is_a($node, 'DOMNode'))
        {
            $xpath = new DOMXPath($node->ownerDocument);
        }
        else
        {
            return false;
        }

        foreach($namespaces as $prefix => $namespaceURI)
        {
            $xpath->registerNamespace($prefix, $namespaceURI);
        }

        $node_list = $xpath->query($xpath_query, $node);

        if($node_list->length > 0)
        {
            foreach($node_list as $node_to_delete)
            {
                if(isset($node_to_delete->parentNode))
                {
                    $node_to_delete->parentNode->removeChild($node_to_delete);
                }
            }
        }
    }
public static function deleteElementsByXpath($node, $xpath_query, $namespaces = array())
    {
        if(is_a($node, 'DOMDocument'))
        {
            $xpath = new DOMXPath($node);
        }
        elseif(is_a($node, 'DOMNode'))
        {
            $xpath = new DOMXPath($node->ownerDocument);
        }
        else
        {
            return false;
        }

        foreach($namespaces as $prefix => $namespaceURI)
        {
            $xpath->registerNamespace($prefix, $namespaceURI);
        }

        $node_list = $xpath->query($xpath_query, $node);

        if($node_list->length > 0)
        {
            foreach($node_list as $node_to_delete)
            {
                if(isset($node_to_delete->parentNode))
                {
                    $node_to_delete->parentNode->removeChild($node_to_delete);
                }
            }
        }
    }
public static function deleteElementsByXpath ( $ node , $ xpath_query , $ namespaces = array ( ) ) { if ( is_a ( $ node , 'DOMDocument' ) ) { $ xpath = new DOMXPath ( $ node ) ; } elseif ( is_a ( $ node , 'DOMNode' ) ) { $ xpath = new DOMXPath ( $ node -> ownerDocument ) ; } else { return false ; } foreach ( $ namespaces as $ prefix => $ namespaceURI ) { $ xpath -> registerNamespace ( $ prefix , $ namespaceURI ) ; } $ node_list = $ xpath -> query ( $ xpath_query , $ node ) ; if ( $ node_list -> length > 0 ) { foreach ( $ node_list as $ node_to_delete ) { if ( isset ( $ node_to_delete -> parentNode ) ) { $ node_to_delete -> parentNode -> removeChild ( $ node_to_delete ) ; } } } }
Delete all the nodes from a DOMDocument that are found with the given xpath query

@param DOMNode $node
@param string $xpath_query
@param array $namespaces
@return boolean
Delete all the nodes from a DOMDocument that are found with the given xpath query