<?php
$xml = new DOMDocument("1.0", "ISO-8859-1");
$xml->formatOutput = true;
$xml->preserveWhiteSpace = false;
$xml->loadXML('<?xml version="1.0"?>
<friends>
<friend id="1">
<name>MyTest</name>
<games>5</games>
<wins>3</wins>
</friend>
</friends>');
echo "<xmp>OLD:\n". $xml->saveXML() ."</xmp>";
$xpath = new DOMXPath($xml);
$result = $xpath->query('//friend[@id="1"]/games');
$result2 = $xpath->query('//friend[@id="1"]/wins');
if($result){
$cgames = $result->item(0)->nodeValue;
$result->item(0)->nodeValue = $cgames+1;
}
if($result2){
$cwins = $result2->item(0)->nodeValue;
$result2->item(0)->nodeValue = $cwins+1;
}
echo "
<xmp>NEW:\n". $xml->saveXML() ."</xmp>";