Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
executable file
·
40 lines (31 loc) · 980 Bytes

File metadata and controls

executable file
·
40 lines (31 loc) · 980 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#!/usr/bin/env luajit
local xmlua = require("xmlua")
local xml = [[
<root>
<sub1>text1</sub1>
<sub2>text2</sub2>
<sub3>text3</sub3>
</root>
]]
local document = xmlua.XML.parse(xml)
-- Searches the <root> element
local root_node_set = document:css_select("root")
-- You can use "#" for getting the number of matched nodes
print(#root_node_set) -- -> 1
-- You can access the N-th node by "[]".
-- It's 1-origin like normal table.
local root = root_node_set[1] -- xmlua.Element
print(root:to_xml())
-- <root>
-- <sub1>text1</sub1>
-- <sub2>text2</sub2>
-- <sub3>text3</sub3>
-- </root>
-- Searches all sub elements under the <root> element
local all_subs = root:css_select("*")
-- You can use "#" for getting the number of matched nodes
print(#all_subs) -- -> 3
-- You can access the N-th node by "[]".
print(all_subs[1]:to_xml()) -- -> <sub1>text1</sub1>
print(all_subs[2]:to_xml()) -- -> <sub2>text2</sub2>
print(all_subs[3]:to_xml()) -- -> <sub3>text3</sub3>
Morty Proxy This is a proxified and sanitized view of the page, visit original site.