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?
Asked
Active
Viewed 2,655 times
3
-
It's actually [libxml2 which doesn't support it](http://programmers.stackexchange.com/questions/205580/why-doesnt-libxml2-support-xpath-2-0). There are a few [XQuery implementations for PHP](http://stackoverflow.com/questions/2211743/execute-a-xquery-with-php) though. Else you'll have to rewrite it for one of the fluent DOM frontends perhaps. – mario Jan 25 '15 at 23:40
1 Answers
3
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.

kjhughes
- 106,133
- 27
- 181
- 240