Execute a XQuery with PHP

前端 未结 8 836
青春惊慌失措
青春惊慌失措 2020-11-30 13:02

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

Thank you.

8条回答
  •  攒了一身酷
    2020-11-30 13:12

    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.

提交回复
热议问题