I am new wih xml file .. I want to get the latest node id value
of xml file using php script and calculate it when I add one more node to this xml file .. something like this ..<id>2</id>
and the next node will be <id>3</id>
after adding...
suppose that i have an xml file like below:
<?xml version="1.0" encoding="UTF-8"?>
<books>
<book>
<id>1</id>
<name>Java</name>
</book>
<book>
<id>2</id>
<name>c++</name>
</book>
</books>
can you guide me which's way to solve this with php script ...thank for advance .
now i had found my solution
//auto id
$doc = new DOMDocument();
libxml_use_internal_errors(true);
$doc->loadXML(file_get_contents ('../books.xml')); // loads your xml
$xpath = new DOMXPath($doc); ///create object xpath
$nlist = $xpath->query("//books/book/id");
$count = $nlist->length; //count number of node
$id = $nlist->item($count-1)->nodeValue;
$id+=1;
echo $id ;
//end auto id
so, you can get the increment one value to $id when inserting new node.