|
0
|
1 <?xml version="1.0"?>
|
|
|
2 <tool id="xpath" name="XPath" version="@WRAPPER_VERSION@.0">
|
|
|
3 <description>compute xpath expressions on XML data</description>
|
|
|
4 <macros>
|
|
|
5 <import>macros.xml</import>
|
|
|
6 </macros>
|
|
|
7 <expand macro="requirements"/>
|
|
|
8 <expand macro="stdio"/>
|
|
|
9 <command interpreter="bash"><![CDATA[xpath
|
|
|
10 -q
|
|
|
11 -e '$expression' $input > $output
|
|
|
12 ]]></command>
|
|
|
13 <inputs>
|
|
|
14 <param name="input" type="data" format="xml" label="Input XML data"/>
|
|
|
15 <param name="expression" type="text" label="XPath Query">
|
|
|
16 <sanitizer>
|
|
|
17 <valid>
|
|
|
18 <add value="""/>
|
|
|
19 <add value="["/>
|
|
|
20 <add value="]"/>
|
|
|
21 <add value="@"/>
|
|
|
22 </valid>
|
|
|
23 </sanitizer>
|
|
|
24 </param>
|
|
|
25 </inputs>
|
|
|
26 <outputs>
|
|
|
27 <!-- TODO: sometimes there's text output (e.g. text() queries) -->
|
|
|
28 <data format="xml" name="output" label="XPath expression on $input.name"/>
|
|
|
29 </outputs>
|
|
|
30 <tests>
|
|
|
31 <test>
|
|
|
32 <param name="input" value="test.xml"/>
|
|
|
33 <param name="expression" value="//b[@attr="value"]" />
|
|
|
34 <output name="output" file="1.xml"/>
|
|
|
35 </test>
|
|
|
36 <test>
|
|
|
37 <param name="input" value="test.xml"/>
|
|
|
38 <param name="expression" value="//b[@attr]" />
|
|
|
39 <output name="output" file="2.xml"/>
|
|
|
40 </test>
|
|
|
41 <test>
|
|
|
42 <param name="input" value="test.xml"/>
|
|
|
43 <param name="expression" value="//b/text()" />
|
|
|
44 <output name="output" file="3.xml"/>
|
|
|
45 </test>
|
|
|
46 </tests>
|
|
|
47 <help><![CDATA[
|
|
|
48 **What it does**
|
|
|
49
|
|
|
50 Query XML files with XPath expressions.
|
|
|
51
|
|
|
52 For an example input file::
|
|
|
53
|
|
|
54 <root>
|
|
|
55 <IdList>
|
|
|
56 <Id>1234</Id>
|
|
|
57 <Id>1235</Id>
|
|
|
58 <Id>1236</Id>
|
|
|
59 <Id>1237</Id>
|
|
|
60 </IdList>
|
|
|
61 </root>
|
|
|
62
|
|
|
63 One could query out the IDs specifically with a query like::
|
|
|
64
|
|
|
65 //Id/text()
|
|
|
66
|
|
|
67 **XPath Expressions**
|
|
|
68
|
|
|
69 There are many helpful tutorials on the internet for XPath expressions.
|
|
|
70 `Wikipedia <https://en.wikipedia.org/wiki/XPath>`__ has a number of good
|
|
|
71 examples.
|
|
|
72
|
|
|
73 **Some More Examples**
|
|
|
74
|
|
|
75 For an XML document like the following::
|
|
|
76
|
|
|
77 <root>
|
|
|
78 <a>
|
|
|
79 <b attr="value">1</b>
|
|
|
80 <b attr="none">2</b>
|
|
|
81 <b>3</b>
|
|
|
82 </a>
|
|
|
83 <c>
|
|
|
84 <d>4</d>
|
|
|
85 <e>5</e>
|
|
|
86 </c>
|
|
|
87 </root>
|
|
|
88
|
|
|
89 Here are some example queries and their outputs:
|
|
|
90
|
|
|
91 +====================+===================================================+
|
|
|
92 | Query | Result |
|
|
|
93 +--------------------+---------------------------------------------------+
|
|
|
94 | //b[@attr="value"] | <b attr="value">1</b> |
|
|
|
95 +--------------------+---------------------------------------------------+
|
|
|
96 | //b[@attr] | <b attr="value">1</b><b attr="none">2</b> |
|
|
|
97 +--------------------+---------------------------------------------------+
|
|
|
98 | //b | <b attr="value">1</b><b attr="none">2</b><b>3</b> |
|
|
|
99 +--------------------+---------------------------------------------------+
|
|
|
100 | //b/text() | 1\n2\n3 |
|
|
|
101 +--------------------+---------------------------------------------------+
|
|
|
102 | /root/*/*/text() | 1\n2\n3\n4\n5 |
|
|
|
103 +--------------------+---------------------------------------------------+
|
|
|
104
|
|
|
105
|
|
|
106
|
|
|
107 @ATTRIBUTION@
|
|
|
108 ]]></help>
|
|
|
109 </tool>
|