PluginProbe
Wp-Insert / 1.7
Wp-Insert v1.7
trunk 1.0 1.1 1.2 1.2.1 1.2.2 1.3.0 1.3.1 1.3.3 1.4 1.5.0 1.5.1 1.5.2 1.5.3 1.6.0 1.6.1 1.6.2 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 2.0 All 63 releases
wp-insert / fckeditor / editor / _source / classes / fckxml.js

fckxml.js in Wp-Insert 1.7, at fckeditor/editor/_source/classes/fckxml.js

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