dojox/wire/XmlWire.js

  • Provides:

    • dojox.wire.XmlWire
  • Requires:

    • dojox.xml.parser in common
    • dojox.wire.Wire in common
  • dojox.wire.XmlWire

    • type
      Function
    • chains:
      • dojox.wire.Wire: (prototype)
      • dojox.wire.Wire: (call)
    • summary
      Initialize properties
    • description
      'args' is just mixed in with no further processing.
    • parameters:
      • args: (typeof Object)
        Arguments to initialize properties
        path:
        A simplified XPath to an attribute, a text or elements
    • source: [view]
        // summary:
        //  Initialize properties
        // description:
        //  'args' is just mixed in with no further processing.
        // args:
        //  Arguments to initialize properties
        //  path:
        //   A simplified XPath to an attribute, a text or elements
  • dojox.wire.XmlWire._wireClass

    • summary
  • dojox.wire.XmlWire._getValue

    • type
      Function
    • parameters:
      • object: (typeof Node)
        A root node
    • source: [view]
        if(!object || !this.path){
         return object; //Node
        }


        var node = object;
        var path = this.path;
        var i;
        if(path.charAt(0) == '/'){ // absolute
         // skip the first expression (supposed to select the top node)
         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; //undefined
         }
        }
        var value = this._getNodeValue(node, list[last]);
        return value; //String||Array
    • summary
      Return an attribute value, a text value or an array of elements
    • description
      This method first uses a root node passed in 'object' argument
      and 'path' property to identify an attribute, a text or
      elements.
      If 'path' starts with a slash (absolute), the first path
      segment is ignored assuming it point to the root node.
      (That is, "/a/b/@c" and "b/@c" against a root node access
      the same attribute value, assuming the root node is an element
      with a tag name, "a".)
    • return_summary
      A value found, otherwise 'undefined'
    • returns
      Node|undefined|String||Array
  • dojox.wire.XmlWire._setValue

    • type
      Function
    • parameters:
      • object: (typeof Node)
        A root node
      • value: (typeof String)
        A value to set
    • source: [view]
        if(!this.path){
         return object; //Node
        }


        var node = object;
        var doc = this._getDocument(node);
        var path = this.path;
        var i;
        if(path.charAt(0) == '/'){ // absolute
         i = path.indexOf('/', 1);
         if(!node){
          var name = path.substring(1, i);
          node = doc.createElement(name);
          object = node; // to be returned as a new object
         }
         // skip the first expression (supposed to select the top node)
         path = path.substring(i + 1);
        }else{
         if(!node){
          return undefined; //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; //Node
    • summary
      Set an attribute value or a child text value to an element
    • description
      This method first uses a root node passed in 'object' argument
      and 'path' property to identify an attribute, a text or
      elements.
      If an intermediate element does not exist, it creates
      an element of the tag name in the 'path' segment as a child
      node of the current node.
      Finally, 'value' argument is set to an attribute or a text
      (a child node) of the leaf element.
    • returns
      Node|to be returned as a new object|undefined
  • dojox.wire.XmlWire._getNodeValue

    • type
      Function
    • parameters:
      • node: (typeof Node)
        A node
      • exp: (typeof String)
        An expression for attribute, text or elements
    • source: [view]
        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{ // assume elements
         value = [];
         for(var i = 0; i < node.childNodes.length; i++){
          var child = node.childNodes[i];
          if(child.nodeType === 1 /* ELEMENT_NODE */ && child.nodeName == exp){
           value.push(child);
          }
         }
        }
        return value; //String||Array
    • summary
      Return an attribute value, a text value or an array of elements
    • description
      If 'exp' starts with '@', an attribute value of the specified
      attribute is returned.
      If 'exp' is "text()", a child text value is returned.
      Otherwise, an array of child elements, the tag name of which
      match 'exp', is returned.
    • return_summary
      A value found, otherwise 'undefined'
    • returns
      String||Array
  • dojox.wire.XmlWire._setNodeValue

    • type
      Function
    • parameters:
      • node: (typeof Node)
        A node
      • exp: (typeof String)
        An expression for attribute or text
      • value: (typeof String)
        A value to set
    • source: [view]
        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);
         }
        }
        // else not supported
    • summary
      Set an attribute value or a child text value to an element
    • description
      If 'exp' starts with '@', 'value' is set to the specified
      attribute.
      If 'exp' is "text()", 'value' is set to a child text.
  • dojox.wire.XmlWire._getChildNode

    • type
      Function
    • parameters:
      • node: (typeof Node)
        A parent node
      • name: (typeof String)
        A tag name
    • source: [view]
        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 /* ELEMENT_NODE */ && child.nodeName == name){
          if(count == index){
           return child; //Node
          }
          count++;
         }
        }
        return null; //null
    • summary
      Return a child node
    • description
      A child element of the tag name specified with 'name' is
      returned.
      If 'name' ends with an array index, it is used to pick up
      the corresponding element from multiple child elements.
    • return_summary
      A child node
    • returns
      Node|null
  • dojox.wire.XmlWire._getDocument

    • type
      Function
    • parameters:
      • node: (typeof Node)
    • source: [view]
        if(node){
         return (node.nodeType == 9 /* DOCUMENT_NODE */ ? node : node.ownerDocument); //Document
        }else{
         return dojox.xml.parser.parse(); //Document
        }
    • summary
      Return a DOM document
    • description
      If 'node' is specified, a DOM document of the node is returned.
      Otherwise, a DOM document is created.
    • return_summary
      A DOM document
    • returns
      Document
  • dojox.wire

    • type
      Object
    • summary
  • dojox

    • type
      Object
    • summary