Removed ALL junk nodes in xml using php
This is the sample input for the example:
<?xml version="1.0" encoding="UTF-8"?>
<root>
    <!--comment1-->
    <elem>a</elem>
    <junk>b</junk>
    <elem>
        <!--comment2-->
        <junk>c<junk>d</junk></junk>
    </elem>
    <!--comment3-->
    <junk>e</junk>
</root>
This is the resulting XML:
<?xml version="1.0" encoding="UTF-8"?>
<root>
    <elem>a</elem>
    <elem>
    </elem>
</root>
I look documents and applied like this:
$doc = new DOMDocument();
$doc->loadXML($xml);
$xpath = new DOMXPath($doc);
foreach ($xpath->query('/root/') as $elem) {
    $elem->parentNode->removeChild($elem);
}
for my case will remove all node "junk" and they will everywhere in xml document.