Delete XML Node if empty?

stewarthawk

New Member
I'm trying to figure out how to delete a bunch of nodes if they are empty. I have tried this but with no luck:\[code\]$xml = new DOMDocument();$xml->preserveWhiteSpace = false;$xml->formatOutput = true;$xml->loadXML('<library> <invites> <invite> <username>0</username> <userid>0</userid> </invite> </invites> <invites/> <invites/> <invites/> <invites/> <invites/> <invites/></library>');echo "<xmp>OLD \n". $xml->saveXML() ."</xmp>";$opNodes = $xml->getElementsByTagName('invites');foreach($opNodes as $node) { //$innerHtml = trim($node->nodeValue); if(empty($node)){ $gameNode = $node->parentNode; $gameNode->parentNode->removeChild($gameNode); }}echo "<xmp>NEW \n". $xml->saveXML() ."</xmp>";\[/code\]I want to delete/remove all the but it doesn't... Please help and thanks in advance :-)
 
Back
Top