<strong>두 개의 데모 코드는 다음과 같습니다(ie에만 해당). </strong> <br><br> <br><br><strong> </strong><br>//demo3(firefox용) <br> <br> <br> TITLE ><br> Firefox의 xml 처리가 IE의 selectSingleNode selectNodes 메소드와 호환되도록 합니다. <br> <br> <br> <br><!-- <BR> <br><!-- <br>var isIE = !! document.all <BR><BR>function parseXML(st){ <BR> if (isIE){ <BR> var result = new ActiveXObject( " microsoft.XMLDOM " ); <BR> result.loadXML(st) <BR> } else { <BR> var parser = new DO MParser(); 파서 .parseFromString(st, " text/xml " ); <BR> } <BR> 반환 결과 <br>} <br><BR>if ( !isIE){ <BR> var ex; 프로토타입 .__proto__.__defineGetter__( " xml " , function (){ <BR> try { <BR> return new XMLSerializer().serializeToString(this); <BR> } catch (ex){ <BR> var d = document. createElement( " div " ); <BR> d.appendChild( this .cloneNode( true )) <BR> return d.innerHTML; <BR> } <BR> }) type.__proto__.__defineGetter__( " xml " , function (){ <BR> try { <BR> return new XMLSerializer().serializeToString(this) <BR> } catch (ex){ <BR> var d = document.createElement( " div " ) ; d.appendChild( this .cloneNode( true )); <BR> return d.innerHTML; <BR> } <BR> }) <BR> XMLDocument.prototype.__proto__ .__defineGetter__( " text " , function () 🎜> return this .firstChild.textContent <BR> }); <BR> Element.prototype.__proto__.__defineGetter__( " text " , function (){ <BR> return this .textContent <BR> }) <BR><BR><BR><br><br> XMLDocument.prototype.selectSingleNode = Element.prototype.selectSingleNode = function (xpath){ <br> var x = this .selectNodes(xpath) <br> if(! x || x .length < 1 ) return null <BR> return x[ 0 ];<BR> XMLDocument.prototype.selectNodes = Element.prototype.selectNodes = 함수(xpath){ <BR> var xpe = new XPathEvaluator(); <BR> var nsResolver = xpe.createNSResolver( this .ownerDocument == null ? <BR> 이 .documentElement : this .ownerDocument.documentElement); <BR> var 결과 = xpe.evaluate(xpath, this , nsResolver, 0 , null ); <BR> var 찾음 = []; <BR> var res; <BR> 동안 (res = result.iterateNext()) <BR> found.push(res); <BR> 반품 찾음; <BR> } <BR>} <br><br>var x = parseXML( " <people> <person first-name= " eric " middle-initial= " H " last-name= " jung " > <address street= " 321 south st " city= " denver " state= " co " country= " usa " /> <address street= " 123 main st " city= " arlington " state= " ma " country= " usa " /> </person> <person first-name= " jed " last-name= " brown " > <address street= " 321 north st " city= " atlanta " state= " ga " country= " usa " /> <address street= " 123 west st " city= " seattle " state= " wa " country= " usa " /> <address street= " 321 south avenue " city= " denver " state= " co " country= " usa " /> </person> </people> ' ); <br><br>alert( " 搜索所有人姓氏(성) " ) <BR>var 결과 = x.selectNodes( " //person/@last-name " ); <BR>for ( var i = 0 ; i < results.length;i ) < results.length;i ) <BR> alert( " Person # " i " 성이 성 " results[i].nodeValue); <br><br>alert( " 搜索第two个人 " ); <BR>// IE是以0为下标基数的,而不是1 <BR>if ( ! document.all) <BR> 결과 = x.selectSingleNode( " /people/person[2] " ); <BR>else <BR> 결과 = x.selectSingleNode( " /people/person[1] " ); <BR>alert(results.xml) <br><br>alert( " 获得住址在donver街上的人 " ); <BR>결과 = x.selectNodes( " //person[address/@city='denver'] " ); <BR>for ( var i = 0 ; i < results.length;i )alert(results[i].xml) < results.length;i )alert(results[i].xml) <br><br>if ( ! document.all){ <BR> // 获得所有街名中带south的地址 <BR> 결과 = x.selectNodes( " //address[contains(@street, 'south')] " ); <BR> 경고(결과[ 0 ].xml); <BR>} else { <BR> alert( " IE不支持 //address[contains(@street, 'south')] 这种查询方式 " ) <BR>}<BR>// --> <br> SCRIPT > <br> HEAD > <br><br> <br><br> BODY > <br> HTML > <br><br> //demo4(크로스 브라우저) <br><a href="http://kb.mozillazine.org/XPath">http://kb.mozillazine.org/XPath</a><br>