Submitting XPath Queries
Once XIA has been unpacked into a directory and that directory added
to the compilation include path, just "with" the
and call the XPath_Query procedure, passing it a starting node (such as the
root document node) and an XPath formatted query. Then use the
Node_List functions to access the nodes in the returned list.
-- Apply an XPath query, starting with the given node, in the case
-- of a relative XPath query, or the document that contains the
-- given node, otherwise. Returns a list of nodes, which may be
-- empty, that meet the XPath specification. If the query does
-- not follow XPath syntax, the Malformed_XPath exception is
(N : Dom.Core.Node;
-- A node in the XML tree against which the XPath query is
XPath : String
-- The XPath query.
) return Dom.Core.Node_List;
Current Status of XIA
This version of XIA implements the XPath 1.0 specification (albeit
with one limitation). Optimization and further refinements will take place in
subsequent releases. This is the first full public release that is intended for
The one limitation is that while the id() core library function is
implemented, it is inoperable, as the underlying XMLAda tool set does not
The txia_test.txt file, containing a list of XPath queries that
seriously exercise the predicate filtering capabilities of XIA, has been
updated to 151 queries. An auxiliary test XML file and associated queries has
been added that focuses on element names that match those of XML keywords (it
contains 13 queries).
Reports of errors (either in operation or in the nodes retrieved)
would be appreciated. Please provide the XML document (or readable fragment),
the query that was submitted, and a description of what was expected.
The test directory contains a test_xpath program, a simple XML file
and associated DTD, the keyword testing XML file, and a script (txia) to run
the test program and feed it a list of XPath queries (txia_tests.txt and
keyword_content_tests.txt) for testing. txia_results.txt contains the expected
output of executing the txia script.
Please send bug reports and questions to
Axes? Predicates? A [very] brief XPath Overview
XPath is readily available on the web. The
purpose of this overview is to provide some basics so that the capabilities of
the current beta version will be understood.
An XPath query resembles a directory path specification:
(Especially for a simple query like that.)
An XPath query is more formally termed a "location path", with each
component of the path called a "location step". The above query has four
location steps: "personnel", "person", "name", and "given". The leading slash
("/") indicates that the path must start at the top of the DOM document. Two
slashes "//") would signify that this path is being sought starting anywhere in
the document, while no slash would mean that the path must start at whatever
node was provided to the XPath query function as a starting point.
A location step consists of three parts:
So all the steps of the above query imply the default child axis,
and each performs a node test checking that the node is an element having the
given tag. No predicate is specified, so every element in the document having
the <given> tag would be selected.
Axis - Can be child (the default), parent, ancestor, or one of
Node Test - Checks the kind of node, such as element, text, or
Predicate - Filters nodes based on the content of the node
//ancestor::name returns every "name"
node in the document that is an ancestor of some another node.
There is a large variety of predicate specifications, please see the
references at the bottom of this page for more information on those.
System Configuration Information
Requires the GNAT Ada compiler. Verified with GNAT 3.15p and gcc
3.4.2 on Linux
Verified with Red Hat Linux 8.0 and 9.0
Verified on Cygwin 1.5.12 with gcc 3.3.3
©2006 McKae Technologies