Package scriptella.driver.xpath

XPath Driver for Scriptella.

See: Description

Package scriptella.driver.xpath Description

XPath Driver for Scriptella.

Allows querying an XML file based on XPath expressions.

General information

Driver class:scriptella.driver.xpath.Driver
URL:XML file URL. URIs are resolved relative to a script file directory.
Runtime dependencies:None

Driver Specific Properties

Name Description Required
return_arrays Value of true specifies that variables should return a string array, otherwise a single string is returned. No, the default value is false.

Query Syntax

XPath driver supports XPath syntax to query text files.

The query is executed on an XML Document and produces a rowset for matched nodes. The attribute and element values can be referenced from nested scripts/queries. The following example illustrates the querying mechanism:

Example:

XPath: /A selects root element <A>

<A B="1">
    <B>2</B>
    <C>3</C>
</A>
Available variables for matched element <A>:
NameValue
A2 3
B1
C3
The value of variable A represents text content inside XML element <A>, the value of variable B represents value of B attribute and the value of variable C represents text content inside element <C>.

The context node for the XPath query is the selected node of the nearest outer XPath query, or the document root node if there isn't one. This allows relative queries using ./

A special node variable is available to the nested queries/scripts which provides extra methods for querying relative to the current node. The node variable is an instance of NodeVariable. Using ${node.getString("./C")} is equivalent to $C.

Additional notes:

Script Syntax

<script> elements are not supported by the driver.

Properties substitution

In query elements ${property} or $property syntax is used for properties/variables substition.

Examples

<connection id="in" driver="xpath" url="data.xml"/>
<connection id="out" driver="text" url="report.csv"/>

<query connection-id="in">
    /HTML/BODY/TABLE/TR
    <script connection-id="out">
        $rownum;${td[0]};${td[1]}
    </script>
</query>

Extracts rows from tables in data.xml file and produces report.csv.

Copyright © Copyright 2006-2012 The Scriptella Project Team.