This repository was archived by the owner on Jan 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCGXMLObject.js
More file actions
executable file
·57 lines (54 loc) · 1.46 KB
/
CGXMLObject.js
File metadata and controls
executable file
·57 lines (54 loc) · 1.46 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
////////////////////////////////////////////////
// XMLtoObject (XML Object Extention)
// Gary Burgess (gary@heavy-rotation.net)
// May 08, 2003
//
// CGXMLObject (Constructor Function)
// Philip Saa (psaa@cowglow.com)
// May 17, 2003
////////////////////////////////////////////////
XML.prototype.toObject = function ()
{
var $xparse = function (n)
{
var o = new String (n.firstChild.nodeValue), s, i, t
for (s = (o == "null") ? n.firstChild : n.childNodes[1]; s != null; s = s.nextSibling)
{
t = s.childNodes.length > 0 ? arguments.callee (s) : new String (s.nodeValue)
for (i in s.attributes) t[i] = s.attributes[i]
if (o[s.nodeName] != undefined)
{
if (!(o[s.nodeName] instanceof Array)) o[s.nodeName] = [o[s.nodeName]]
o[s.nodeName].push (t)
}
else o[s.nodeName] = t
}
return o
}
return $xparse (this)
}
////////////////////////////////////////////////
_global.CGXMLObject = function(xmlDoc){
this.objXML = new XML();
this.objXML.ignoreWhite = true;
this.objXML.master = this;
this.objXML.onLoad = function(success){
if (success){
this.master.all = this.toObject();
this.master.onLoad();
}
delete this;
}
this.objXML.load(xmlDoc);
}
///////////////////////////////////////////////////////
// Usage
///////////////////////////////////////////////////////
//
// myXMLObject = new CGXMLObject(xmlDoc.xml);
//
// myXMLObject.onLoad = (){
// // Some logic here.
// }
//
///////////////////////////////////////////////////////