How to execute a XQuery in PHP? Can you give me an example?
Thank you.
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.
Use BaseX. Its stable, scaleable, and fast! (but you need a server to run)
BaseX clients
include("BaseXClient.php");
$session = new Session("localhost", 1984, "admin", "admin");
print $session->execute("xquery 1 to 10");
$session->close();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With