XML Extraction Examples
The examples below make queries against the document XMLExtractionExamples1.xml: AM represents an attribute mark, VM a value mark and SVM a subvalue mark.
Example 1 - Simple attribute lookup
Query
<server> <services> <service name="Devices" port="%1%"/> </services> </server>
Result
5300
Comments
Extracts the value of the port
attribute from the <service>
node with the name
attribute "Devices".
Example 2 - Simple attribute lookup; attributes reversed
Query
<server> <services> <service port="5001" name="%1%" /> </services> </server>
Result
Time
Comments
Extracts the value of the name
attribute from the <service>
node with the port
attribute "5001". Note that the fixed,
defining attribute (port="5001"
) appears before the attribute
containing the extraction sequence (name="%1%"
).
Example 3 - Simple attribute lookup; multiple matches
Query
<server> <services> <service name="Time" port="%1%"/> </services> </server>
Result
5001VM5002
Comments
Extracts the value of the port
attribute from the <service>
node with the name
attribute "Time". Because the query node
has no sibling nodes, the query can match multiple document nodes at the same
level. The result therefore includes values from all matching document nodes,
separated by value marks.
Example 4 - Multiple attribute lookup; single matches
Query
<server> <services> <service name="Time" port="%1%"/> <service name="MultiGateWay" port="%2%"/> </services> </server>
Result
5001am
5100
Comments
Extracts the values of the port
attributes from the <service>
nodes with the names
attribute "Time" and "MultiGateWay".
The "Time" value is placed in attribute 1 and "MultiGateWay" in
attribute 2. Note that the <service>
nodes in the query are in the same
order as in the XML document. If the "Time" node had been placed after "MultiGateWay",
only the latter value would have matched because there are no "Time" nodes
following the first "MultiGateWay" node (see
Sequential Mode).
Example 5 - Multiple attribute lookup; multiple matches
Query
<server> <services __nis_cont="P"> <service name="Time" port="%1%"/> <service name="MultiGateWay" port="%2%"/> </services> </server>
Result
5001VM5002aM
5100VM6100
Comments
This example is similar to Example 4, but the
<services>
node includes a __nis_cont
attribute to change to
parallel processing mode. As a
result, values from all matching nodes are returned, because the order in which
they appear in the XML document is no longer significant.
Example 6 - Multiple attribute result; no tabulation
Query
<server> <services> <service name="SingleGateWay" port="%1%" realport="%2%" destport="%3%"/> </services> </server>
Result
5101VM5102VM5103AM
101VM102VM103aM
23
Comments
Extracts the values of the port,
realport
and
destport
attributes from the <service>
node with the name
attribute "SingleGateWay". Because the
query node has no sibling nodes, the query can match multiple document nodes at
the same level. The attributes in the result therefore include values from all
matching document nodes, separated by value marks (the last attribute contains
only a single multivalue because only the first of the matching nodes contains a
destport
attribute).
Example 7 - Multiple attribute result with tabulation
Query
<server> <services __nis_cont="T"> <service name="SingleGateWay" port="%1%" realport="%2%" destport="%3%"/> </services> </server>
Result
5101VM5102VM5103aM
101VM102VM103aM
23VMVM
Comments
This example is similar to Example 6, but the
<services>
node includes a __nis_cont
attribute to change to
tabulation mode. As a result,
the final attribute contains blank multivalues, corresponding to the missing
destport
attributes.
Example 8 - Single line node value
Query
<server>
<comment>%1%</comment>
</server>
Result
Simple comment
Comments
Extracts the value of the <comment>
node.
Example 9 - Multi-line node value
Query
<server>
<description>%1%</description>
</server>
Result
Line 1 of description
Line 2 of description
Comments
Extracts the value of the <description>
node. In the result,
leading and trailing white space is discarded and the lines are separated by new
line characters.
Example 10 - Extract complete node
Query
<server>
<terminal-ports>
%1%
</terminal-ports>
</server>
Result
<entry device="COM2" service="TerminalPort" port="5602" realport="202"/> <entry device="COM3" service="TerminalPort" port="5603" realport="203"/>
Comments
Extracts all the child nodes from the <terminal-ports>
node. In the
result, leading and trailing white space is discarded and the lines are
separated by new line characters.