topical media & game development

talk show tell print

professional-ajax-04-XPath-IE-zxml.js / js



  var a={b:(typeof ActiveXObject!="undefined"),z:document.implementation&&document.implementation.createDocument,d:(typeof XMLHttpRequest!="undefined")};a.ARR_XMLHTTP_VERS=["MSXML2.XmlHttp.5.0","MSXML2.XmlHttp.4.0","MSXML2.XmlHttp.3.0","MSXML2.XmlHttp","Microsoft.XmlHttp"];a.ARR_DOM_VERS=["MSXML2.DOMDocument.5.0","MSXML2.DOMDocument.4.0","MSXML2.DOMDocument.3.0","MSXML2.DOMDocument","Microsoft.XmlDom"];function zXmlHttp(){};zXmlHttp.createRequest=function(){if(a.useXmlHttp){return new XMLHttpRequest();}else if(a.useActiveX){if(!a.XMLHTTP_VER){for(var i=0;i<a.ARR_XMLHTTP_VERS.length;i++){try{new ActiveXObject(a.ARR_XMLHTTP_VERS[i]);a.XMLHTTP_VER=a.ARR_XMLHTTP_VERS[i];break;};catch(e){}}};if(a.XMLHTTP_VER){return new ActiveXObject(a.XMLHTTP_VER);}else{throw new Error("Could not create XML HTTP Request.");}}else{throw new Error("Your browser doesn't support an XML HTTP Request.");}};function zXmlDom(){};zXmlDom.createDocument=function(){if(a.useDom){var f=document.implementation.createDocument("","",null);f.parseError={valueOf:function(){return this.errorCode;},toString:function(){return this.errorCode.toString()}};f.L();f.addEventListener("load",function(){this.M();this.N(4);},false);return f;}else if(a.useActiveX){if(!a.DOM_VER){for(var i=0;i<a.ARR_DOM_VERS.length;i++){try{new ActiveXObject(a.ARR_DOM_VERS[i]);a.DOM_VER=a.ARR_DOM_VERS[i];break;};catch(e){}}};if(a.DOM_VER){return new ActiveXObject(a.DOM_VER);}else{throw new Error("Could not create XML DOM document.");}}else{throw new Error("Your browser doesn't support an XML DOM document.");}};var g=null;if(typeof h!="undefined"){g=h;}else if(typeof Document!="undefined"){g=Document;};if(g&&!window.opera){g.prototype.readyState=0;g.prototype.onreadystatechange=null;g.prototype.N=function(i){this.readyState=i;if(typeof this.onreadystatechange=="function"){this.onreadystatechange();}};g.prototype.L=function(){this.parseError.errorCode=0;this.parseError.filepos=-1;this.parseError.line=-1;this.parseError.linepos=-1;this.parseError.reason=null;this.parseError.srcText=null;this.parseError.url=null;};g.prototype.M=function(){if(this.documentElement.tagName=="parsererror"){var j=/>([\s\S]*?)Location:([\s\S]*?)Line Number(\d+), Column(\d+):<sourcetext>([\s\S]*?)(?:\-*^)/;j.test(this.xml);this.parseError.errorCode=-999999;this.parseError.reason=RegExp.$1;this.parseError.url=RegExp.$2;this.parseError.line=parseInt(RegExp.$3);this.parseError.linepos=parseInt(RegExp.$4);this.parseError.srcText=RegExp.$5;}};g.prototype.loadXML=function(k){this.L();this.N(1);var l=new DOMParser();var f=l.parseFromString(k,"text/xml");while(this.firstChild){this.removeChild(this.firstChild);};for(var i=0;i<f.childNodes.length;i++){var m=this.importNode(f.childNodes[i],true);this.appendChild(m);};this.M();this.N(4);};g.prototype.O=g.prototype.load;g.prototype.load=function(n){this.L();this.N(1);this.O(n);};Node.prototype.__defineGetter__("xml",function(){var o=new XMLSerializer();return o.serializeToString(this,"text/xml");});Node.prototype.__defineGetter__("text",function(){var p="";for(var i=0;i<this.childNodes.length;i++){if(this.childNodes[i].hasChildNodes()){p+=this.childNodes[i].text;}else{p+=this.childNodes[i].nodeValue;}};return p;});};function zXslt(){};zXslt.transformToText=function(q,r){if(typeof s!="undefined"){var t=new s();t.importStylesheet(r);var u=t.transformToDocument(q);var v=u.xml;if(v.indexOf("<transformiix:result")>-1){v=v.substring(v.indexOf(">")+1,v.lastIndexOf("<"));};return v;}else if(a.useActiveX){return q.transformNode(r);}else{throw new Error("No XSLT engine found.");}};function zXPath(){};zXPath.selectNodes=function(w,x,y){if(typeof z!="undefined"){A=A||{};var B=function(Z){return A[Z];};var D=new z();var E=D.evaluate(x,w,B,F.ORDERED_NODE_ITERATOR_TYPE,null);var G=new Array;if(E!=null){var H=E.iterateNext();while(H){G.push(H);H=E.iterateNext();}};return G;}else if(a.useActiveX){if(A){var y="";for(var I in A){y+="xmlns:"+I+"="+A[I]+" ";};w.ownerDocument.setProperty("SelectionNamespaces",y);};return w.selectNodes(x);}else{throw new Error("No XPath engine found.");}};zXPath.selectSingleNode=function(w,x,A){if(typeof z!="undefined"){A=A||{};var B=function(Z){return A[Z];};var D=new z();var E=D.evaluate(x,w,B,F.FIRST_ORDERED_NODE_TYPE,null);if(E!=null){return E.singleNodeValue;}else{return null;}else if(J.useActiveX){if(A){var y="";for(var I in A){y+="xmlns:"+I+"="+A[I]+" ";};w.ownerDocument.setProperty("SelectionNamespaces",y);};return w.selectSingleNode(x);}else{throw new Error("No XPath engine found.")}};function zXMLSerializer(){};zXMLSerializer.prototype.serializeToString=function(K){var k="";switch(K.nodeType){case 1:k="<"+K.tagName;for(var i=0;i<K.attributes.length;i++){k+=" "+K.attributes[i].name+"=\"" + oNode.attributes[i].value + "\"";};k+=">";for(var i=0;i<K.childNodes.length;i++){k+=this.serializeToString(K.childNodes[i]);};k+="</"+K.tagName+">";break;case 3:k=K.nodeValue;break;case 4:k="<![CDATA["+K.nodeValue+"]]>";break;case 7:k="<?"+K.nodevalue+"?>";break;case 8:k="<!--"+K.nodevalue+"-->";break;case 9:for(var i=0;i<K.childNodes.length;i++){k+=this.serializeToString(K.childNodes[i]);};break;};return k;};
  
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.