File tree Expand file tree Collapse file tree 1 file changed +17
-2
lines changed
docs/Runtime Environment/Library Reference Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -7,14 +7,15 @@ Returns a table representing the XML data.
7
7
``` pluto
8
8
local xml = require "pluto:xml"
9
9
10
- print(dumpvar( xml.decode([[
10
+ local root = xml.decode([[
11
11
<entries>
12
12
<entry type="primary">
13
13
<name>primary</name>
14
14
</entry>
15
15
</entries>
16
- ]])))
16
+ ]])
17
17
18
+ print(dumpvar(root))
18
19
--> {
19
20
--> ["tag"] = string(7) "entries",
20
21
--> ["children"] = {
@@ -35,6 +36,20 @@ print(dumpvar(xml.decode([[
35
36
--> },
36
37
--> }
37
38
```
39
+
40
+ For ease of use, the returned tables have an ` __index ` metamethod:
41
+ ``` pluto
42
+ -- root is <entries>, so its first child is <entry>.
43
+ -- we make use of the metamethod to get to <name>:
44
+ print(dumpvar(root.children[1].name))
45
+ --> {
46
+ --> ["tag"] = string(4) "name",
47
+ --> ["children"] = {
48
+ --> [1] = string(7) "primary",
49
+ --> },
50
+ --> }
51
+ ```
52
+
38
53
If there is no single root element, a "body" element is implied as the root:
39
54
``` pluto
40
55
local xml = require "pluto:xml"
You can’t perform that action at this time.
0 commit comments