123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- define("dojox/wire/XmlWire", ["dijit","dojo","dojox","dojo/require!dojox/xml/parser,dojox/wire/Wire"], function(dijit,dojo,dojox){
- dojo.provide("dojox.wire.XmlWire");
- dojo.require("dojox.xml.parser");
- dojo.require("dojox.wire.Wire");
- dojo.declare("dojox.wire.XmlWire", dojox.wire.Wire, {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- _wireClass: "dojox.wire.XmlWire",
-
- constructor: function(/*Object*/args){
-
-
-
-
-
-
-
-
- },
- _getValue: function(/*Node*/object){
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if(!object || !this.path){
- return object;
- }
- var node = object;
- var path = this.path;
- var i;
- if(path.charAt(0) == '/'){
-
- i = path.indexOf('/', 1);
- path = path.substring(i + 1);
- }
- var list = path.split('/');
- var last = list.length - 1;
- for(i = 0; i < last; i++){
- node = this._getChildNode(node, list[i]);
- if(!node){
- return undefined;
- }
- }
- var value = this._getNodeValue(node, list[last]);
- return value;
- },
- _setValue: function(/*Node*/object, /*String*/value){
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if(!this.path){
- return object;
- }
- var node = object;
- var doc = this._getDocument(node);
- var path = this.path;
- var i;
- if(path.charAt(0) == '/'){
- i = path.indexOf('/', 1);
- if(!node){
- var name = path.substring(1, i);
- node = doc.createElement(name);
- object = node;
- }
-
- path = path.substring(i + 1);
- }else{
- if(!node){
- return undefined;
- }
- }
- var list = path.split('/');
- var last = list.length - 1;
- for(i = 0; i < last; i++){
- var child = this._getChildNode(node, list[i]);
- if(!child){
- child = doc.createElement(list[i]);
- node.appendChild(child);
- }
- node = child;
- }
- this._setNodeValue(node, list[last], value);
- return object;
- },
- _getNodeValue: function(/*Node*/node, /*String*/exp){
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- var value = undefined;
- if(exp.charAt(0) == '@'){
- var attribute = exp.substring(1);
- value = node.getAttribute(attribute);
- }else if(exp == "text()"){
- var text = node.firstChild;
- if(text){
- value = text.nodeValue;
- }
- }else{
- value = [];
- for(var i = 0; i < node.childNodes.length; i++){
- var child = node.childNodes[i];
- if(child.nodeType === 1 && child.nodeName == exp){
- value.push(child);
- }
- }
- }
- return value;
- },
- _setNodeValue: function(/*Node*/node, /*String*/exp, /*String*/value){
-
-
-
-
-
-
-
-
-
-
-
-
- if(exp.charAt(0) == '@'){
- var attribute = exp.substring(1);
- if(value){
- node.setAttribute(attribute, value);
- }else{
- node.removeAttribute(attribute);
- }
- }else if(exp == "text()"){
- while(node.firstChild){
- node.removeChild(node.firstChild);
- }
- if(value){
- var text = this._getDocument(node).createTextNode(value);
- node.appendChild(text);
- }
- }
-
- },
- _getChildNode: function(/*Node*/node, /*String*/name){
-
-
-
-
-
-
-
-
-
-
-
-
-
- var index = 1;
- var i1 = name.indexOf('[');
- if(i1 >= 0){
- var i2 = name.indexOf(']');
- index = name.substring(i1 + 1, i2);
- name = name.substring(0, i1);
- }
- var count = 1;
- for(var i = 0; i < node.childNodes.length; i++){
- var child = node.childNodes[i];
- if(child.nodeType === 1 && child.nodeName == name){
- if(count == index){
- return child;
- }
- count++;
- }
- }
- return null;
- },
- _getDocument: function(/*Node*/node){
-
-
-
-
-
-
-
- if(node){
- return (node.nodeType == 9 ? node : node.ownerDocument);
- }else{
- return dojox.xml.parser.parse();
- }
- }
- });
- });
|