-
Notifications
You must be signed in to change notification settings - Fork 7
/
README
133 lines (112 loc) · 4.03 KB
/
README
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# Introduction #
This is a small library to use plist files for flash contents.
Details
Features list
XML based property list support
plist 1.0 support
access properties directly using dot syntax
Binary based property list support (tentative)
# Getting Started #
1. load plist file with URLLoader and prepare to capture event from URLLoader.
public function init():void
{
var loader:URLLoader=new URLLoader(new URLRequest("sample.plist"));
loader.addEventListener(Event.COMPLETE, onComplete);
}
2. create an instace and use parse() method with loaded data. That's all.
private function onComplete(e:Event):void
{
var plist:Plist10=new Plist10();
plist.parse(e.target.data);
}
# For Binary Format #
Invoke getXML method before parse loaded data within onComplete method.
public function init():void
{
var loader:URLLoader=new URLLoader(new URLRequest("sample_bin.plist"));
loader.dataFormat = URLLoaderDataFormat.BINARY;
loader.addEventListener(Event.COMPLETE, onComplete);
}
private function onComplete(e:Event):void
{
var plist:Plist10=new Plist10();
plist.parse(Bin2Xml.getXML(e.target.data));
}
# Access Plist Node Value #
Get value
Use 'parent dot child' to reach parent's child element.
trace(plist.root.false_key); //false
You want XMLList?
Use reserved keyword named 'xml' to get its own XMLList object.
trace(plist.root.arr_key[0].arr_child_dic); // null
trace(plist.root.arr_key[0].xml); //<dict><key>arr_child_dic</key><string>null</string></dict>
You should use toXMLString() for no collective types because they will be converted to string automatically.
trace(plist.root.false_key.xml); //false_key (toString() works silently)
trace(plist.root.false_key.xml.toXMLString()); //<key>false_key</key>
Use .object property
Reserved word 'object' is useful to view whole object created from XML.
parsed from XML below.
<key>arr_key</key>
<array>
<string>111111</string>
<string>222222</string>
</array>
sample using .object property
trace(plist.root.arr_key); //11111,22222
trace(plist.root.arr_key[0]); //11111
trace(plist.root.arr_key.object); //11111,22222
Node Exists or not?
All elements are derived from PlistElement class and you can check if they exists or not using 'is'.
trace(plist.root.dic_key);
trace(plist.root.dic_key is PlistElement);//true
trace(plist.root.dic_key2);
trace(plist.root.dic_key2 is PlistElement);//false
Type of nodes
You should check the type of object property of node when you want to know the type of node.
trace(plist.root.arr_key is Array); //false
trace(plist.root.arr_key.object is Array); //true
sample.plst
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>New item</key>
<data>
</data>
<key>arr_key</key>
<array>
<dict>
<key>arr_child_dic</key>
<string>null</string>
</dict>
<string>str_data</string>
<true/>
<integer>0</integer>
<array>
<string>111111</string>
<string>222222</string>
</array>
</array>
<key>date_key</key>
<date>2008-07-18T13:35:27Z</date>
<key>dic_key</key>
<dict>
<key>child_key</key>
<string>dic_child_data</string>
</dict>
<key>false_key</key>
<false/>
<key>num_key</key>
<integer>0</integer>
<key>num_key_2</key>
<real>0.23011999999999999</real>
<key>str_key</key>
<string>Hello</string>
<key>true_key</key>
<true/>
</dict>
</plist>
# CDATA #
CDATA directive is useful to write html tags in xml. You do not have to care about escape strings.
<string><a href="http://www.google.com">hello</a></string>
<string><![CDATA[<a href="http://www.google.com">hello</a>]]></string>