XIA (XPath In Ada) is a native Ada implementation of the XPath 1.0 specification. XIA is built using the DOM component of AdaCore's XML/Ada implementation and AdaGOOP.
Submitting XPath queries is done via the XPath_Query
function in package XIA
. The function returns a Node_List, as defined in DOM.Core
, whose contents can be accessed with the Item
function in DOM.Core.Nodes
.
The test program test_xpath opens an XML file into the DOM.Readers.Tree_Reader
(XML_Source_Reader
) and then executes queries, producing results in a DOM.Core.Node_List
(Queried_Nodes
):
Queried_Nodes :=
Xpath_Query (Dom.Readers.Get_Tree (XML_Source_Reader), Query);
For each query, it prints out the number of matching nodes and an image of the contents of each.
For this XML file, modelled loosely on a Wikipedia example,
<a name="a1">
<b name="b1">
<c name="c1"/>
<d name="d1"/>
</b>
<b name="b2">
<e name="e1"/>
</b>
<x name="x1">
<b name="b3">
<f name="f1"/>
</b>
</x>
</a>
the query
a//b/*[1]/@name
finds 3 nodes, the first child of each <b/>
node in the document:
Number of nodes: 3
name="c1"
name="e1"
name="f1"
whereas the query
(a//b/*)[1]/@name
finds one node, the child node of the first <b/>
node:
Number of nodes: 1
name="c1"
A BASH script, txia
, and an input file of XPath queries, txia_tests.txt
, are provided in the test/
directory to jam a bunch of queries through the test program (if more test queries are added, be sure to leave an empty line after all the queries - text after an empty line is ignored). txia_tests.txt
also exhibits a wide variety of XPath queries, although the majority of these are nonsense queries as far as realistic usage is concerned, they're tailored to exercise and test various aspects of XIA's implementation.
To generate the test program, cd
to the test directory and say alr build
.
Version history up to 1.00 is here.
Please report issues at Github.
- Github maintainer: Simon Wright [email protected]
- Original author: Marc A. Criley [email protected]