I want to get the value of last id in item element. For example, in the xml below, I want to get value 2 and increment one for the id for next item entered. So if the next item is entered, the id will automatically be 3 and so on. Tried couple ways but I still cant get it to work. Any suggestions? items.xml
<?xml version="1.0"?>
<items>
<item>
<id>1</id>
<name>N95</name>
<desc>Nokia</desc>
<price>299</price>
<quantity>11</quantity>
</item>
<item>
<id>2</id>
<name>S4</name>
<desc>Samsung</desc>
<price>500</price>
<quantity>50</quantity>
</item>
</items>
php file
$x = file_get_contents('../../data/items.xml');
$root = $x->documentElement; //root element(items)
$lastId = $root->lastChild->firstChild->firstChild->nodeValue; //navigate to get the value of last item id
$newItemId = $lastId + 1;