1
2
11
12
29 class com.sekati.data.XML2Object {
30
31 private var oResult:Object = new Object( );
32 private var oXML:XML;
33
34
40 public function get xml():XML {
41 return oXML;
42 }
43
44
52 function parseXML(sFile:XML):Object {
53 this.oResult = new Object( );
54 this.oXML = sFile;
55 this.oResult = this.translateXML( );
56 return this.oResult;
57 }
58
59
62 private function translateXML(from:Object, path:Object, name:Object, position:Object):Object {
63 var xmlName:String;
64 var nodes:Object, node:Object, old_path:Object;
65 if (path == undefined) {
66 path = this;
67 name = "oResult";
68 }
69 path = path[name];
70 if (from == undefined) {
71 from = new XML( this.xml.toString( ) );
72 from.ignoreWhite = true;
73 }
74 if (from.hasChildNodes( )) {
75 nodes = from.childNodes;
76 if (position != undefined) {
77 old_path = path;
78 path = path[position];
79 }
80 while (nodes.length > 0) {
81 node = nodes.shift( );
82 xmlName = node.nodeName;
83 if (xmlName != undefined) {
84 var __obj__:Object = new Object( );
85 __obj__.attributes = node.attributes;
86 __obj__.data = node.firstChild.nodeValue;
87 if (position != undefined) {
88 old_path = path;
89 }
90 if (path[xmlName] != undefined) {
91 if (path[xmlName].__proto__ == Array.prototype) {
92 path[xmlName].push( __obj__ );
93 name = node.nodeName;
94 position = path[xmlName].length - 1;
95 } else {
96 var copyObj:Object = path[xmlName];
97 path[xmlName] = new Array( );
98 path[xmlName].push( copyObj );
99 path[xmlName].push( __obj__ );
100 name = xmlName;
101 position = path[xmlName].length - 1;
102 }
103 } else {
104 path[xmlName] = __obj__;
105 name = xmlName;
106 position = undefined;
107 }
108 }
109 if (node.hasChildNodes( )) {
110 this.translateXML( node, path, name, position );
111 }
112 }
113 }
114 return this.oResult;
115 }
116 }