forked from skn3/xml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example1.monkey
66 lines (57 loc) · 1.67 KB
/
example1.monkey
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
Import mojo
Import xml
'--- test program---
Class TestApp Extends App
Method OnCreate:Int()
Local error:= New XMLError
Local ms:Int = Millisecs()
Local doc:= ParseXML(LoadString("test2.xml"), error)
Print "took " + (Millisecs() -ms)
If doc = Null and error.error
'error
Print error.ToString()
Else
'success
'get all books
Print "[get title of all books]"
Local nodes:= doc.GetDescendants("title")
For Local node:= EachIn nodes
Print node.value
Next
Print ""
'get all fantasy books
Print "[get all fantasy books]"
nodes = doc.GetDescendants("genre", "@value=Fantasy")
For Local node:= EachIn nodes
Print node.GetParent().GetChild("title").value
Next
Print ""
'get null book
Print "[get null attribute from null node]"
Print doc.GetChild("this_doesnt_exist").GetAttribute("some_value", "default_value")
Print ""
'print node paths for all books by Corets, Eva
Print "[get paths to all books by Corets, Eva]"
nodes = doc.GetDescendants("author", "@value=Corets, Eva")
For Local node:= EachIn nodes
Print node.GetParent().GetChild("title").value + " at '" + node.GetParent().path + "'"
Next
Print ""
'get node at path
Print "[get description of first book at path book/description]"
Print doc.GetChildAtPath("book/description").value
Print ""
'get node at path with attributes
Print "[get title of first book at path book/genre where genre value is Fantasy]"
Print doc.GetChildAtPath("book/genre", "@value=Fantasy").GetParent().GetChild("title").value
Print ""
EndIf
'quit the app
Error ""
Return True
End
End
Function Main:Int()
New TestApp
Return True
End