PHP does not have any native or common XML parsers that support XQuery (If I'm wrong, someone let me know). It does however have two pretty standard extensions that handle XPath queries.
I personally think simplexml
is the better of the two. You would simply use:
$xml = new simplexml($some_xml_string);
$xpath_results = $xml -> Xpath("//a/b");
And then loop through the results.
The extensive DOM class supports Xpath queries as well. The only real advantage, as far as I see it, to using DOM is that the results can be modified or deleted straight out of the larger XML object.
Good luck.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…