@@ -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 >
@@ -86,19 +86,37 @@ <h2><a name="examples"></a>Examples</h2>
86
86
[[
87
87
<?xml version="1.0" encoding="ISO-8859-1"?>
88
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>
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">text of the new element
94
+ <test>text of the test element</test>
95
+ </test:newElement>
93
96
</root>
94
97
]]
95
98
96
- -- get all elements
99
+ -- get all element nodes
97
100
xpath.selectNodes(lom.parse(xmlTest),'//element')
98
- -- get the subelement text
101
+
102
+ -- get the subelement node's text
99
103
xpath.selectNodes(lom.parse(xmlTest),'/root/element/subelement/text()')
100
- -- get the first element
104
+
105
+ -- get the element with an attribute of "id" that has the value of "1"
101
106
xpath.selectNodes(lom.parse(xmlTest),'/root/element[@id="1"]')
107
+
108
+ -- get the 2nd element node
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
+
102
120
</ pre >
103
121
104
122
< h2 > < a name ="related_docs "> </ a > Related documentation</ h2 >
0 commit comments