import rt 3.8.7
[freeside.git] / rt / share / html / NoAuth / RichText / FCKeditor / editor / _source / classes / fckxml.js
1 /*\r
2  * FCKeditor - The text editor for Internet - http://www.fckeditor.net\r
3  * Copyright (C) 2003-2009 Frederico Caldeira Knabben\r
4  *\r
5  * == BEGIN LICENSE ==\r
6  *\r
7  * Licensed under the terms of any of the following licenses at your\r
8  * choice:\r
9  *\r
10  *  - GNU General Public License Version 2 or later (the "GPL")\r
11  *    http://www.gnu.org/licenses/gpl.html\r
12  *\r
13  *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")\r
14  *    http://www.gnu.org/licenses/lgpl.html\r
15  *\r
16  *  - Mozilla Public License Version 1.1 or later (the "MPL")\r
17  *    http://www.mozilla.org/MPL/MPL-1.1.html\r
18  *\r
19  * == END LICENSE ==\r
20  *\r
21  * FCKXml Class: class to load and manipulate XML files.\r
22  * (IE specific implementation)\r
23  */\r
24 \r
25 var FCKXml = function()\r
26 {\r
27         this.Error = false ;\r
28 }\r
29 \r
30 FCKXml.GetAttribute = function( node, attName, defaultValue )\r
31 {\r
32         var attNode = node.attributes.getNamedItem( attName ) ;\r
33         return attNode ? attNode.value : defaultValue ;\r
34 }\r
35 \r
36 /**\r
37  * Transforms a XML element node in a JavaScript object. Attributes defined for\r
38  * the element will be available as properties, as long as child  element\r
39  * nodes, but the later will generate arrays with property names prefixed with "$".\r
40  *\r
41  * For example, the following XML element:\r
42  *\r
43  *              <SomeNode name="Test" key="2">\r
44  *                      <MyChild id="10">\r
45  *                              <OtherLevel name="Level 3" />\r
46  *                      </MyChild>\r
47  *                      <MyChild id="25" />\r
48  *                      <AnotherChild price="499" />\r
49  *              </SomeNode>\r
50  *\r
51  * ... results in the following object:\r
52  *\r
53  *              {\r
54  *                      name : "Test",\r
55  *                      key : "2",\r
56  *                      $MyChild :\r
57  *                      [\r
58  *                              {\r
59  *                                      id : "10",\r
60  *                                      $OtherLevel :\r
61  *                                      {\r
62  *                                              name : "Level 3"\r
63  *                                      }\r
64  *                              },\r
65  *                              {\r
66  *                                      id : "25"\r
67  *                              }\r
68  *                      ],\r
69  *                      $AnotherChild :\r
70  *                      [\r
71  *                              {\r
72  *                                      price : "499"\r
73  *                              }\r
74  *                      ]\r
75  *              }\r
76  */\r
77 FCKXml.TransformToObject = function( element )\r
78 {\r
79         if ( !element )\r
80                 return null ;\r
81 \r
82         var obj = {} ;\r
83 \r
84         var attributes = element.attributes ;\r
85         for ( var i = 0 ; i < attributes.length ; i++ )\r
86         {\r
87                 var att = attributes[i] ;\r
88                 obj[ att.name ] = att.value ;\r
89         }\r
90 \r
91         var childNodes = element.childNodes ;\r
92         for ( i = 0 ; i < childNodes.length ; i++ )\r
93         {\r
94                 var child = childNodes[i] ;\r
95 \r
96                 if ( child.nodeType == 1 )\r
97                 {\r
98                         var childName = '$' + child.nodeName ;\r
99                         var childList = obj[ childName ] ;\r
100                         if ( !childList )\r
101                                 childList = obj[ childName ] = [] ;\r
102 \r
103                         childList.push( this.TransformToObject( child ) ) ;\r
104                 }\r
105         }\r
106 \r
107         return obj ;\r
108 }\r