dojox/xml/widgetParser.js

  • Provides:

    • dojox.xml.widgetParser
  • Requires:

    • dojox.xml.parser in common
    • dojo.parser in common in project dojo
  • dojox.xml.widgetParser

    • type
      Function
    • ?? initialized = 1 (debug: boolean) ??
    • source: [view]
       var d = dojo;

       
       this.parseNode = function(node){

        
        var toBuild = [];
        //TODO figure out the proper type
        d.query("script[type='text/xml']", node).forEach(function(script){
         toBuild.push.apply(toBuild, this._processScript(script));
        }, this).orphan();

        
        //instantiate everything at the end, doing it piecewise can give ID conflicts
        return d.parser.instantiate(toBuild);
       };


       this._processScript = function(script){
        //the text is either loaded from a separate file by the src
        //attribute or underneath the src tag
        var text = script.src ? d._getText(script.src) : script.innerHTML || script.firstChild.nodeValue;
        var htmlNode = this.toHTML( dojox.xml.parser.parse(text).firstChild );

        
        //make the list BEFORE we copy things over to keep the query scope as
        //small as possible
        var ret = d.query('[dojoType]', htmlNode);
        //remove the script tag and replace with new HTML block
        dojo.query(">", htmlNode).place(script, "before")
        script.parentNode.removeChild(script);
        return ret;
       };

       
       /**
        * Given an XML node converts it to HTML where the existing HTML
        * is preserved and the dojo widget tags are converted to divs
        * with dojoType on them.
        */
       this.toHTML = function (/*XmlNode*/ node){
        var newNode;
        var nodeName = node.nodeName;
        var dd = dojo.doc;
        var type = node.nodeType;

        

        
        ///node type 3 and 4 are text and cdata
        if(type >= 3){
         return dd.createTextNode( (type == 3 || type == 4) ? node.nodeValue : "" );
        }

        
        var localName = node.localName||nodeName.split(":").pop();

        
        //TODO:
        //  only check for namespace ONCE ever, instead of each time here,
        //  by mixing in the right check for each browser?
        var namespace = node.namespaceURI || (node.getNamespaceUri ? node.getNamespaceUri() : "");

        
        //TODO check for some real namespace
        if(namespace == "html"){
         newNode = dd.createElement(localName);
        }else{
         var dojoType = namespace + "." + localName;

         
         /**
          * This is a horrible hack we need because creating a

          * with