-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathexample_test.go
More file actions
42 lines (34 loc) · 770 Bytes
/
example_test.go
File metadata and controls
42 lines (34 loc) · 770 Bytes
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
package xmlpath
import (
"log"
lua "github.com/yuin/gopher-lua"
)
// xmlpath.compile, xmlpath.load, xmlpath_node_ud, xmlpath_path_ud, xmlpath_iter_ud
func Example_full() {
state := lua.NewState()
Preload(state)
source := `
local xmlpath = require("xmlpath")
local data = [[
<channels>
<channel id="1" xz1="600" />
<channel id="2" />
<channel id="x" xz2="600" />
</channels>
]]
local data_path = "//channel/@id"
local node, err = xmlpath.load(data)
if err then error(err) end
local path, err = xmlpath.compile(data_path)
if err then error(err) end
local iter = path:iter(node)
for k, v in pairs(iter) do print(v:string()) end
`
if err := state.DoString(source); err != nil {
log.Fatal(err.Error())
}
// Output:
// 1
// 2
// x
}