root / trunk / web / dojo / dojox / wire / XmlWire.js @ 12
History | View | Annotate | Download (2.47 KB)
1 | 9 | andrej.cim | /*
|
---|---|---|---|
2 | Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
||
3 | Available via Academic Free License >= 2.1 OR the modified BSD license.
|
||
4 | see: http://dojotoolkit.org/license for details
|
||
5 | */
|
||
6 | |||
7 | |||
8 | if(!dojo._hasResource["dojox.wire.XmlWire"]){ |
||
9 | dojo._hasResource["dojox.wire.XmlWire"]=true; |
||
10 | dojo.provide("dojox.wire.XmlWire");
|
||
11 | dojo.require("dojox.xml.parser");
|
||
12 | dojo.require("dojox.wire.Wire");
|
||
13 | dojo.declare("dojox.wire.XmlWire",dojox.wire.Wire,{_wireClass:"dojox.wire.XmlWire",constructor:function(_1){ |
||
14 | },_getValue:function(_2){ |
||
15 | if(!_2||!this.path){ |
||
16 | return _2;
|
||
17 | } |
||
18 | var _3=_2;
|
||
19 | var _4=this.path; |
||
20 | var i;
|
||
21 | if(_4.charAt(0)=="/"){ |
||
22 | i=_4.indexOf("/",1); |
||
23 | _4=_4.substring(i+1);
|
||
24 | } |
||
25 | var _5=_4.split("/"); |
||
26 | var _6=_5.length-1; |
||
27 | for(i=0;i<_6;i++){ |
||
28 | _3=this._getChildNode(_3,_5[i]);
|
||
29 | if(!_3){
|
||
30 | return undefined; |
||
31 | } |
||
32 | } |
||
33 | var _7=this._getNodeValue(_3,_5[_6]); |
||
34 | return _7;
|
||
35 | },_setValue:function(_8,_9){ |
||
36 | if(!this.path){ |
||
37 | return _8;
|
||
38 | } |
||
39 | var _a=_8;
|
||
40 | var _b=this._getDocument(_a); |
||
41 | var _c=this.path; |
||
42 | var i;
|
||
43 | if(_c.charAt(0)=="/"){ |
||
44 | i=_c.indexOf("/",1); |
||
45 | if(!_a){
|
||
46 | var _d=_c.substring(1,i); |
||
47 | _a=_b.createElement(_d); |
||
48 | _8=_a; |
||
49 | } |
||
50 | _c=_c.substring(i+1);
|
||
51 | }else{
|
||
52 | if(!_a){
|
||
53 | return undefined; |
||
54 | } |
||
55 | } |
||
56 | var _e=_c.split("/"); |
||
57 | var _f=_e.length-1; |
||
58 | for(i=0;i<_f;i++){ |
||
59 | var _10=this._getChildNode(_a,_e[i]); |
||
60 | if(!_10){
|
||
61 | _10=_b.createElement(_e[i]); |
||
62 | _a.appendChild(_10); |
||
63 | } |
||
64 | _a=_10; |
||
65 | } |
||
66 | this._setNodeValue(_a,_e[_f],_9);
|
||
67 | return _8;
|
||
68 | },_getNodeValue:function(_11,exp){ |
||
69 | var _12=undefined; |
||
70 | if(exp.charAt(0)=="@"){ |
||
71 | var _13=exp.substring(1); |
||
72 | _12=_11.getAttribute(_13); |
||
73 | }else{
|
||
74 | if(exp=="text()"){ |
||
75 | var _14=_11.firstChild;
|
||
76 | if(_14){
|
||
77 | _12=_14.nodeValue; |
||
78 | } |
||
79 | }else{
|
||
80 | _12=[]; |
||
81 | for(var i=0;i<_11.childNodes.length;i++){ |
||
82 | var _15=_11.childNodes[i];
|
||
83 | if(_15.nodeType===1&&_15.nodeName==exp){ |
||
84 | _12.push(_15); |
||
85 | } |
||
86 | } |
||
87 | } |
||
88 | } |
||
89 | return _12;
|
||
90 | },_setNodeValue:function(_16,exp,_17){ |
||
91 | if(exp.charAt(0)=="@"){ |
||
92 | var _18=exp.substring(1); |
||
93 | if(_17){
|
||
94 | _16.setAttribute(_18,_17); |
||
95 | }else{
|
||
96 | _16.removeAttribute(_18); |
||
97 | } |
||
98 | }else{
|
||
99 | if(exp=="text()"){ |
||
100 | while(_16.firstChild){
|
||
101 | _16.removeChild(_16.firstChild); |
||
102 | } |
||
103 | if(_17){
|
||
104 | var _19=this._getDocument(_16).createTextNode(_17); |
||
105 | _16.appendChild(_19); |
||
106 | } |
||
107 | } |
||
108 | } |
||
109 | },_getChildNode:function(_1a,_1b){ |
||
110 | var _1c=1; |
||
111 | var i1=_1b.indexOf("["); |
||
112 | if(i1>=0){ |
||
113 | var i2=_1b.indexOf("]"); |
||
114 | _1c=_1b.substring(i1+1,i2);
|
||
115 | _1b=_1b.substring(0,i1);
|
||
116 | } |
||
117 | var _1d=1; |
||
118 | for(var i=0;i<_1a.childNodes.length;i++){ |
||
119 | var _1e=_1a.childNodes[i];
|
||
120 | if(_1e.nodeType===1&&_1e.nodeName==_1b){ |
||
121 | if(_1d==_1c){
|
||
122 | return _1e;
|
||
123 | } |
||
124 | _1d++; |
||
125 | } |
||
126 | } |
||
127 | return null; |
||
128 | },_getDocument:function(_1f){ |
||
129 | if(_1f){
|
||
130 | return (_1f.nodeType==9?_1f:_1f.ownerDocument); |
||
131 | }else{
|
||
132 | return dojox.xml.parser.parse();
|
||
133 | } |
||
134 | }}); |
||
135 | } |