XPath is a query language for addressing parts of an XML document. In XSB, this support is provided by the xpath package. To use this package the libxml2 XML parsing library must be installed on the machine. It comes with most Linux distributions, since it is part of the Gnome desktop, or one can download it from http://xmlsoft.org/. It is available for Linux, Solaris, Windows, and MacOS. Note that both the library itself and the .h files of that library must be installed. In some Linux distributions, the .h files might reside in a separate package from the package that contains the actual library. For instance, the library (libxml2.so) might be in the package called libxml2 (which is usually installed by default), while the .h files hight be in the package libxml2-devel (which is usually not in a default installation).
On Unix-based systems (and MacOS), the package needs to be configured using the configure script found in the XSB's packages/xpath directory. The configure script has several options such as -exec-prefix, -prefix, etc, which may need to be specified if the package libxml2 is installed in a non-standard place. In this case, -exec-prefix=directory-of-libxml2 must specify the directory where the lib/libxml2.so file is located and -prefix=include-dir where the include/libxml2 directory is found. The default exec-prefix is /usr/lib and prefix is /usr. If the defaults are fine (they would be, if the Gnome desktop is installed on your machine), then one can configure the package using
./configureOtherwise, use
./configure --prefix=/usr/share --exec-prefix=/usr/localif, for example, libxml2.so is in /usr/local/lib/libxml2.so and the included .h files are in /usr/share/include/libxml2.
On Windows and under Cygwin, the libxml2 library is already included in the XSB distribution and does not need to be downloaded. If you are using a prebuilt XSB distribution for Windows, then you do not need to do anything--the package has already been built for you.
For Cygwin, you only need to run the ./configure script without any options. This needs to be done regardless of whether you downloaded XSB from CVS or a released prebuilt version.
If you downloaded XSB from CVS and want to use it under native Windows (not Cygwin), then you would need to compile the XPath package, and you need Microsoft's Visual Studio. To compile the package one should do the following:
cd packages\xpath\cc
nmake /f NMakefile.mak
The following section assumes that the reader is familiar with the syntax of XPath and its capabilities. To load the xpath package, type
:-[xpath].
The program needs to include the following directive:
:- import parse_xpath/4 from xpath.
XPath query evaluation is done by using the parse_xpath predicate.
XPathQuery is a standard XPath query which is to be evaluated on the XML document in Source.
Output gets bound to the output term. It represents the XML element returned after the XPath query is evaluated on the XML document in Source. The output term is of the form string( 'XML-document'). It can then be parsed using the sgml package described earlier.
NamespacePrefixList is a space separated list of pairs of the form prefix = namespace. This specifies the namespace prefixes that are used in the XPath query.
For example if the xpath expression is '/x:html/x:head/x:meta' where x is a prefix that stands for 'http://www.w3.org/1999/xhtml', then x would have to be defined as follows: