Get XML node position



I have the following XML



<cds>
<record>
<id>1</id>
<artist>Rammstein</artist>
<album>random</album>
<trackNumbers>11</trackNumbers>
</record>
<record>
<id>2</id>
<artist>Rammstein</artist>
<album>random</album>
<trackNumbers>18</trackNumbers>
</record>
</cds>


I want to delete the record by the identifiier "ID" that I pass from another php file. So if I am not wrong I need the position of the record node to remove that node.



$xml=simplexml_load_file("books.xml") or die("Error: Cannot create object");

unset($xml->record[x]); // x should be the id passed


Is this achievable? I've been trying to obtain this I am not able to find the solution.


No comments:

Post a Comment