XPath and php starters
Quick starting point on XPath and php would be the W3C Xpath pages. All the syntax info you really need to build queries are there. One other example i found useful was this one.
Then to use XPath with your php scripts, I use xpath(). A basic example would be the following (explained underneath) – say you have an <item> node which has multiple <title> children nodes, and you want to get a list of all the first children <title> nodes from that xml doc, you could do this:
<?php
$xml = simplexml_load_file(‘path/to/file/xml-file.xml’);
$matches = $xml->xpath(“//item/title[1]“);
foreach ($matches as $match){
echo $match[0] . “<br>”;
}
?>
So firstly we use simplexml_load_file to load our xml file. We then build the query, saying for every item element that appears anywhere in the xml file, select all title elements that are the first (the title elements that appear ‘top’ in the list) children of item elements.
//