Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Evaluate XPath 2.0 in PHP

I am currently working on a project written in PHP and want to evaluate XPath expression on XML files. Since the files are a quite complex, my XPath contains expressions like for...in...return-loops or other features introduced with XPath 2. Unfortunately PHP's DOMXPath class supports only XPath 1.0, and I didn't find any XPath 2.0 evaluator for PHP. Has anybody faced the same problem and found a solution?

like image 717
Sören Oldag Avatar asked Oct 25 '25 06:10

Sören Oldag


1 Answers

Saxon/C (currently in beta) can be called from PHP. It's open source, covered under the Mozilla Public License 2.0. Linux, Windows and Mac OS X are supported.

Alternatively, in lieu of support for XPath 2.0 you could just re-write your XPaths to use XPath 1.0 proper and cover iteration etc outside of XPath in PHP itself.

like image 62
kjhughes Avatar answered Oct 26 '25 21:10

kjhughes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!