This repository was archived by the owner on Aug 9, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathMain.hx
More file actions
63 lines (47 loc) · 1.48 KB
/
Copy pathMain.hx
File metadata and controls
63 lines (47 loc) · 1.48 KB
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
package;
// http://old.haxe.org/api/haxe/xml/fast
// http://old.haxe.org/doc/advanced/xml_fast
class Main {
public static function main () {
trace("--------------------------------------------------------------");
trace("--- Read element's information with xml-fast ---");
var str:String = "
<user name='john'>
<phone>
<number>0000</number>
<number>111</number>
</phone>
</user>
";
// parse some xml data
var xml:Xml = Xml.parse(str);
// wrap the xml for fast access
var fast = new haxe.xml.Fast(xml.firstElement());
// access attributes
trace(fast.att.name); // attribute "name"
if(fast.has.age)
trace(fast.att.age); // optional attribute
// access the "phone" child, which is wrapped with haxe.xml.Fast too
var phone = fast.node.phone;
// iterate over numbers
for(p in phone.nodes.number)
trace(p.innerData);
trace("--------------------------------------------------------------");
trace("--- Show text of element (if contained) with xml-fast ---");
str = "
<root>
<myNode1>This if text of element 'myNode1'...</myNode1>
<myNode2></myNode2>
<myNode3/>
</root>
";
xml = Xml.parse(str);
fast = new haxe.xml.Fast(xml.firstElement());
if (fast.node.myNode1.innerHTML > "")
trace(fast.node.myNode1.innerHTML);
if (fast.node.myNode2.innerHTML > "")
trace(fast.node.myNode2.innerHTML);
if (fast.node.myNode3.innerHTML > "")
trace(fast.node.myNode3.innerHTML);
}
}