Possible Duplicate:
Grabbing the href attribute of an A element
I have an xml chat script in which I add new chats via php. But at the same time I want to be able to update a specific users badge in the xml, but simply can't figure out how?
Here is my xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<data>
<players>
<player id="1">4</player>
<player id="2">3</player>
</players>
<chats>
<chat playerid="2">Some chat here...</chat>
<chat playerid="1">skfgjh kjgh fdskgjhdf kgjhdf gkjd gkjdfhg dkfjhg</chat>
</chats>
</data>
And here is the php in which I add a new chat:
$file = 'chat.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");
$library = $xml->documentElement;
$message = $xml->createElement("chat","sdlkj oghdfiguh fdiugh eiuh eriu irgh eigu ekgjher");
$messageAttribute = $xml->createAttribute('playerid');
$messageAttribute->value = $opponent;
$message->appendChild($messageAttribute);
$library->childNodes->item(1)->appendChild($message);
echo "<xmp>". $xml->saveXML() ."</xmp>";
I have tried to add this but with no luck:
$xmlPath = new DOMXPath($xml);
$xmlNode = $xmlPath->query('//player[id="1"]');
I want to change the 4 to say 0.
Can somebody please help :-/