//--------------------------------------------------------------------------------------------------- // 格式化XML的trace窗口输出,更容易阅读 //XML.format() : Format your XML for easy reading. XML.prototype.__proto__.format = function(t) { var a, i, s; if (this.nodeName == null) { s = this.firstChild.format(t); return s;} s = "<"+this.nodeName; for (a in this.attributes) { s += " "+a+"=\""+this.attributes[a]+"\"";} if (!this.hasChildNodes()) { s += " />"; return t+s+newline; } s += ">"; if (this.firstChild.nodeType == 3) { s += this.firstChild.nodeValue; } else { s += newline; for (i=0; i"; return t+s+newline; }; //usage /* I tried the other versions of this type of function but none of them displayed in proper XML format, so here is one that will. I tested it the best I could, but I don't have any confidence in myself so I apologize now if you find any problems. Feel free to mention any fixes or improvements you may have. */ myXML = new XML('C'); trace(myXML.format("")); /* Will output: C */ //-------------------------------------------------------------------------------------------------- //解释xml为标签引用可行 //----------------------------------------------------------- // XMLNode.makeXMLSA 1.0 by Max Ziebell // 12/07/2004 - fixed little bug on attributes // - added id-attribute hook generation // 11/25/2004 - initial release // // based on XML.makeObj by J.Milkins //----------------------------------------------------------- XMLNode.prototype._mxr = function(f){return this[0][f];} XMLNode.prototype._mxp = function(xObj, obj) { var c, nName, nType, cNode, cId; //----- Add attributes to the object obj.attributes = {}; var oa = obj.attributes; var xa = xObj.attributes; for (c in xa) oa[c] = xa[c]; //----- Build child nodes for (c in xObj.childNodes) { cNode = xObj.childNodes[c]; nName = cNode.nodeName; nType = cNode.nodeType; if (nType == 3) { obj._value = cNode.nodeValue; }else if (nType == 1 && nName != null) { if (!(obj[nName] instanceof Array)){ obj[nName] = new Array(); obj[nName].__resolve = this._mxr; ASSetPropFlags(obj[nName],null,1,1); } var sObj = this._mxp(cNode, {}); obj[nName].unshift(sObj); // comment the next line to disable id-attribute hooks cId = cNode.attributes.id; if (cId!=undefined and obj[cId]==undefined) obj[cId] = sObj; } } // Return object return obj; }; //wrapper for _mxp XMLNode.prototype.makeXMLSA = function(noRoot) { return (noRoot==true) ? this._mxp(this.firstChild,{}) : this._mxp(this,{}); }; //hide from for..in ASSetPropFlags(XMLNode.prototype,['makeXMLSA','_mxp','_mxr'],1,1); //useage /* http://www.nike.com this was a job for nike http://www.audi.com this job was made with Flash A flyer */ // first parse the Data (see above box) xmlString = 'http://www.nike.comthis was a job for nikehttp://www.audi.comthis job was made with FlashA flyer'; // [NOTE] used firstChild=makeXMLSA(true) here so we woun't end up with portfolio.portfolio portfolio = new XML(xmlString) portfolio = portfolio.makeXMLSA(true); trace("XMLNode.makeXMLSA EXAMPLES\n");trace("direct access on values:"); //outputs "http://www.nike.com" trace("\tportfolio.web.job.href._value = "+portfolio.web.job.href._value); //outputs "http://www.nike.com" (the same but we used a index on job!) trace("\tportfolio.web.job[0].href._value = "+portfolio.web.job[0].href._value); //outputs "http://www.audi.com" (we used the second index on job ...starting at 0!) trace("\tportfolio.web.job[1].href._value = "+portfolio.web.job[1].href._value); //do a loop when ever you want because its allways a array! trace("\nnow in a loop over jobs in web:"); for (var c=0;c