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