@@ -73,7 +73,7 @@ <h2><a name="usage"></a>Usage</h2>
73
73
require "luaxpath"
74
74
local lom = require "lxp.lom"
75
75
76
- xpath.selectNodes(lom.parse(xmlString),xpathExpression)
76
+ xpath.selectNodes(lom.parse(xmlString),xpathExpression,ignoreCase )
77
77
</ pre >
78
78
79
79
< h2 > < a name ="examples "> </ a > Examples</ h2 >
@@ -85,20 +85,54 @@ <h2><a name="examples"></a>Examples</h2>
85
85
local xmlTest =
86
86
[[
87
87
<?xml version="1.0" encoding="ISO-8859-1"?>
88
- <root>
89
- <element id="1" name="element1">text of the first element</element>
90
- <element id="2" name="element2">
91
- <subelement>text of the second element</subelement>
92
- </element>
88
+ <root xmlns:test="https://test.test/">
89
+ <element id="1" name="element1">text of the first element</element>
90
+ <element id="2" name="element2">
91
+ <subelement>text of the second element</subelement>
92
+ </element>
93
+ <test:newElement id="1" name="newElement">
94
+ <test>text of the test element</test>
95
+ </test:newElement>
93
96
</root>
94
97
]]
95
98
96
99
-- get all elements
97
100
xpath.selectNodes(lom.parse(xmlTest),'//element')
101
+
98
102
-- get the subelement text
99
103
xpath.selectNodes(lom.parse(xmlTest),'/root/element/subelement/text()')
100
- -- get the first element
104
+
105
+ -- get the element by attribute id 1
101
106
xpath.selectNodes(lom.parse(xmlTest),'/root/element[@id="1"]')
107
+
108
+ -- get node two by index
109
+ xpath.selectNodes(lom.parse(xmlTest),'/root/element[2]')
110
+
111
+ -- get the first element node, with ignoring the case of element
112
+ xpath.selectNodes(lom.parse(xmlTest),'/root/ELEMENT[1]',true)
113
+
114
+ -- get the newElement node and make use of the namespace in the tag name
115
+ xpath.selectNodes(lom.parse(xmlTest),'/root/test:newElement')
116
+
117
+ -- get the node that has a child node that contains a tag name of subelement
118
+ xpath.selectNodes(lom.parse(xmlTest),'//element[name="subelement"]')
119
+
120
+ -- get any node that has an attribute of test
121
+ xpath.selectNodes(lom.parse(xmlTest),'//*/@test')
122
+
123
+ -- get the node by name
124
+ xpath.selectNodes(lom.parse(xmlTest),'/root/element/node()')
125
+
126
+ -- get all child nodes of root
127
+ xpath.selectNodes(lom.parse(xmlTest),'/root/*')
128
+
129
+ -- get all child nodes of root that contains an attribute of name which is equal to element
130
+ xpath.selectNodes(lom.parse(xmlTest),'/root/element[contains(@name, "element")]')
131
+
132
+ -- get all element nodes that contains an attribute of name which starts with ele
133
+ xpath.selectNodes(lom.parse(xmlTest),'/root/element[starts-with(@name, "ele")]')
134
+
135
+
102
136
</ pre >
103
137
104
138
< h2 > < a name ="related_docs "> </ a > Related documentation</ h2 >
0 commit comments