6

Does anybody know which version of the XPath specification has been implemented in XML::LibMXL?

Or more to the point, where can I find a description of the XPath functions that I can use in LibXML?

For example, I tried something like

$dcDOM->findvalue('//dc:identifier[contains(@xsi:type,"URI")]');

which seems to work fine, but

$dcDOM->findvalue('//dc:identifier[matches(@xsi:type,"URI")]');

does not.

From that one has to assume that it supports at most XPath 1.0 or some subset of 1.0/2.0 .

Is there a neat page where everything is listed and described?

jackthehipster
  • 978
  • 8
  • 26

3 Answers3

11

As you surmised from your probe, XML::LibXML supports XPath 1.0 (not 2.0).

Generally speaking, there is no way in XPath itself to ascertain the version other than through such probes. XSLT, on the other hand, provides system-property('xsl:version') for identifying version information.

Going the source heritage route: XML::LibXML is based on libxml2, which implements XPath 1.0, as stated right on the Libxml2 homepage:

Libxml2 implements a number of existing standards related to markup languages:

     XML Path Language (XPath) 1.0: http://www.w3.org/TR/xpath

You might ask Why doesn't libxml2 support XPath 2.0? or read an old post from maintainer Daniel Veillard that says that XPath 2.0 spec is "far too big and intrusive," but the bottom line remains: XML::LibXML supports XPath 1.0, not 2.0.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
kjhughes
  • 106,133
  • 27
  • 181
  • 240
2

XML::LibXML is an interface to libxml, so you would need to find out what version of that you have installed. How you do that depends on your OS, but you could check the version of xsltproc or xmllint, e.g.:

$ xsltproc --version
Using libxml 20900, libxslt 10128 and libexslt 817
xsltproc was compiled against libxml 20900, libxslt 10128 and libexslt 817
libxslt 10128 was compiled against libxml 20900
libexslt 817 was compiled against libxml 20900

So I've got libxml v2.2.9.

According to the source of all wisdom, Wikipedia, libxml2 only implements XPath 1.0.

i alarmed alien
  • 9,412
  • 3
  • 27
  • 40
  • Good point, but I have no idea how to check that in Windows... it must be libxml 2.x. But anyway from my question I assume it supports XPath 1.0, since matches() doesn't work. – jackthehipster Oct 02 '14 at 15:05
  • @jackthehipster that's the quickest way to find out - try some definitely-2.0 expression like `for $a in . return $a` and see if it complains. – Ian Roberts Oct 02 '14 at 15:13
  • 1
    @jackthehipster the other thing that very strongly suggests it's 1.0-only is that the documentation talks about "node sets" rather than "sequences" and describes types as "number" and "string" rather than referring to the XML Schema types used by v2.0 – Ian Roberts Oct 02 '14 at 15:14
  • 2
    @jackthehipster there is a partial extension to libxml2 that implements some XPath2.0 functionality [here](http://www.explain.com.au/libx/), but it doesn't look like it's a going concern any more. If you need XPath 2.0, there is an open-source [javascript implementation](https://github.com/ilinsky/xpath.js), and saxon (Java) also supports XPath 2.0 – i alarmed alien Oct 02 '14 at 16:12
1

Ok, this is not the 100% answer, but according to https://stackoverflow.com/a/10655581/2740187 (from 2012) libxml only supports XPath 1.0, and the supported string functions are described here: http://www.w3.org/TR/xpath/#section-String-Functions.

Community
  • 1
  • 1
jackthehipster
  • 978
  • 8
  • 26