XML PHP Delete specific Child if?

pandabearpxsvk

New Member
I have a xml document looking like this:\[code\]<?xml version="1.0" encoding="ISO-8859-1"?><library> <invites> <invite> <username>0</username> <userid>0</userid> </invite> <invite> <username>Danielle</username> <gameid>87808</gameid> </invite> <invite> <username>Petra</username> <userid>978</userid> </invite> </invites></library>\[/code\]Now, I want to delete the \[code\]<invite>\[/code\] with Danielle but I am not sure how? I am using this right now but this will only delete the first record?\[code\]$file = 'my.xml';$fp = fopen($file, "rb") or die("cannot open file");$str = fread($fp, filesize($file));$xml = new DOMDocument("1.0", "ISO-8859-1");$xml->formatOutput = true;$xml->preserveWhiteSpace = false;$xml->loadXML($str) or die("Error");$root = $xml->documentElement;$fnode = $root->firstChild;$ori = $fnode->childNodes->item(0);$fnode->removeChild($ori);$xml->save($file);\[/code\]I want to be able to delete depending on either gameid or userid. How do I go about this?Thanks in advance :-)
 
Back
Top