forked from skn3/xml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample7.monkey
49 lines (41 loc) · 952 Bytes
/
example7.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
#TEXT_FILES="*.xml"
Import mojo
'Import monkey
Import xml
Function Main()
Local error:XMLError = New XMLError
Local doc:XMLDoc = ParseXML(LoadString("data.xml"), error)
Local node:XMLNode = Null
If error.error = False
Print "without text nodes:"
OutputNode(doc, 0, False)
Print ""
Print ""
Print "with text nodes:"
OutputNode(doc, 0, True)
Else
Print "error: " + error.ToString()
EndIf
Print "finished!"
End
Function OutputNode(node:XMLNode, depth:Int = 0, text:Bool = False)
Local build:String
For Local index:= 0 Until depth
build += "-"
Next
If node.text
build += " (text) " + node.value
Else
build += " (node) " + node.name + " (value=" + node.value+")"
EndIf
Print build
If text or node.text = False
Local pointer:= node.GetChild(text)
While pointer.valid
If text or pointer.text = False
OutputNode(pointer, depth + 1, text)
EndIf
pointer = pointer.GetNextSibling()
Wend
EndIf
End