Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute a XQuery with PHP

Tags:

php

xquery

How to execute a XQuery in PHP? Can you give me an example?

Thank you.

like image 939
abernier Avatar asked Feb 06 '10 02:02

abernier


2 Answers

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.

like image 97
Anthony Avatar answered Sep 23 '22 01:09

Anthony


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();
like image 35
lacmuch Avatar answered Sep 23 '22 01:09

lacmuch