search
  • Sign In
  • Sign Up
Password reset successful

Follow the proiects vou are interested in andi aet the latestnews about them taster

Home Backend Development XML/RSS Tutorial FireFox's processing of XML is compatible with IE's node processing method

FireFox's processing of XML is compatible with IE's node processing method

Feb 27, 2017 pm 04:17 PM

Make Firefox's xml processing compatible with IE's node processing method. The specific codes are listed below.

The specific code is as follows.

<! DOCTYPE Html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > 
< HTML > 
< HEAD > 
< TITLE >  使firefox对xml的处理兼容IE的selectSingleNode selectNodes方法  </ TITLE > 
< META  NAME ="Author"  CONTENT ="emu" > 
< META  NAME ="KeyWords"  CONTENT ="firefox IE selectSingleNode selectNodes" > 
< META  NAME ="Description"  CONTENT ="使firefox可以支持selectSingleNode selectNodes方法" > 
< SCRIPT  LANGUAGE ="javascript" > 
<!-- 
var  isIE  =   !! document.all;
function  parseXML(st){
     if (isIE){
         var  result  =   new  ActiveXObject( " microsoft.XMLDOM " );
        result.loadXML(st);
    } else {
         var  parser  =   new  DOMParser();
         var  result  =  parser.parseFromString(st,  " text/xml " );
    }
     return  result;
}
if ( ! isIE){
     var  ex;
    XMLDocument.PRototype.__proto__.__defineGetter__( " xml " ,  function (){
         try {
             return   new  XMLSerializer().serializeToString( this );
        } catch (ex){
             var  d  =  document.createElement( " div " );
            d.appendChild( this .cloneNode( true ));
             return  d.innerHTML;
        }
    });
    Element.prototype.__proto__.__defineGetter__( " xml " ,  function (){
         try {
             return   new  XMLSerializer().serializeToString( this );
        } catch (ex){
             var  d  =  document.createElement( " div " );
            d.appendChild( this .cloneNode( true ));
             return  d.innerHTML;
        }
    });
    XMLDocument.prototype.__proto__.__defineGetter__( " text " ,  function (){
         return   this .firstChild.textContent
    });
    Element.prototype.__proto__.__defineGetter__( " text " ,  function (){
         return   this .textContent
    });
    XMLDocument.prototype.selectSingleNode = Element.prototype.selectSingleNode = function (XPath){
         var  x = this .selectNodes(xpath)
         if ( ! x    x.length < 1 ) return   null ;
         return  x[ 0 ];
    }
    XMLDocument.prototype.selectNodes = Element.prototype.selectNodes = function (xpath){
         var  xpe  =   new  XPathEvaluator();
         var  nsResolver  =  xpe.createNSResolver( this .ownerDocument  ==   null   ? 
             this .documentElement :  this .ownerDocument.documentElement);
         var  result  =  xpe.evaluate(xpath,  this , nsResolver,  0 ,  null );
         var  found  =  [];
         var  res;
         while  (res  =  result.iterateNext())
            found.push(res);
         return  found;
    }
}
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> " );
alert( " 搜索所有人的姓氏(last-name) " )
var  results  =  x.selectNodes( " //person/@last-name " );
for  ( var  i = 0 ; i < results.length;i ++ )
  alert( " Person # "   +  i  +   "  has the last name  "   +  results[i].nodeValue);
alert( " 搜索第二个人 " );
//  IE是以0为下标基数的,而不是1 
if ( ! document.all)
    results  =  x.selectSingleNode( " /people/person[2] " );
else 
    results  =  x.selectSingleNode( " /people/person[1] " );
alert(results.xml)
alert( " 获得住址在donver街上的人 " );
results  =  x.selectNodes( " //person[address/@city='denver'] " );
for  ( var  i = 0 ; i < results.length;i ++ )alert(results[i].xml)
if ( ! document.all){
     //  获得所有街名中带south的地址 
    results  =  x.selectNodes( " //address[contains(@street, 'south')] " );
    alert(results[ 0 ].xml);
} else {
    alert( " IE不支持 //address[contains(@street, 'south')] 这种查询方式 " )
}
// --> 
</ SCRIPT > 
</ HEAD > 
< BODY > 
</ BODY > 
</ HTML >

As you can see from the example, IE's support for xpath is still limited.

The above is the content of FireFox’s processing of XML that is compatible with IE’s node processing method. For more related content, please pay attention to the PHP Chinese website (m.sbmmt.com)!


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

ArtGPT

ArtGPT

AI image generator for creative art from text prompts.

Stock Market GPT

Stock Market GPT

AI powered investment research for smarter decisions

Popular tool

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Working with XML attributes vs. elements: design choices Working with XML attributes vs. elements: design choices Sep 14, 2025 am 01:21 AM

UseattributesformetadatasuchasID,status,orunit,whichdescribetheelementbutarenotcorecontent,ensuringsimplicityandcompactnesswhendataisatomic.2.Useelementsforactualdatacontent,especiallywhenitmayrequirestructure,repetition,extensibility,orfuturenesting

A Comparison of XML Libraries in the Python Ecosystem A Comparison of XML Libraries in the Python Ecosystem Sep 09, 2025 am 02:19 AM

ForbasicXMLtaskswithnodependencies,usexml.etree.ElementTree;2.ForadvancedfeatureslikeXPathandXSLT,chooselxml;3.Forverylargefiles,usexml.saxorlxml’siterparseformemoryefficiency;4.Forlearningorlegacycode,xml.dom.minidomisacceptable;5.Formalformedorinco

A Guide to XML Canonicalization (C14N) A Guide to XML Canonicalization (C14N) Aug 27, 2025 am 06:08 AM

XMLCanonicalization(C14N)solvestheproblemofsyntacticvariabilityinXMLbyensuringlogicallyequivalentdocumentsproduceidenticalbytesequences,whichiscriticalfordigitalsignaturesandsecurecomparisons.1.CanonicalXML(C1.0)providesfullnormalizationwithattribute

python xml etree elementtree findall example python xml etree elementtree findall example Sep 24, 2025 am 02:25 AM

Use findall() to find all matching elements in XML. 1. Get all book elements through root.findall('book') and traverse; 2. Use book.find('title').text to extract child element text; 3. Use book.get('id') to obtain attribute values; 4. Support simple XPaths such as 'book[@id]' or './/title' to find attributes or deep nested elements; 5. Conditional filtering needs to be manually implemented (such as price > 40). This method returns a list of matching elements, combining find() and findtext() can efficiently extract structured data.

A Deep Dive into XPath for XML Navigation A Deep Dive into XPath for XML Navigation Sep 28, 2025 am 12:26 AM

XPath is a powerful query language for efficient navigation and selection of XML document nodes. 1. It accurately locates elements and attributes through path expressions; 2. Supports filtering conditions based on name, attribute, text content and location; 3. Use axis (such as child, parent, and ancestor) to implement context-aware node traversal; 4. Common in various environments such as Python, Java, Selenium, etc.; 5. Suitable for scenarios such as configuration file parsing, SOAP response extraction, and web page automation; 6. Over-dependence should be avoided when using //, and priority is given to using named attributes and logical combination conditions to improve stability; 7. Expressions can be tested and verified through browser developer tools or XML editor; 8. Although in large

How to Handle Character Encoding Issues in XML Files How to Handle Character Encoding Issues in XML Files Sep 03, 2025 am 02:18 AM

AlwaysdeclareencodingexplicitlyintheXMLdeclarationusingUTF-8,asitensurescompatibilityandavoidsambiguity.2.EnsuretheactualfileencodingmatchesthedeclaredencodingbyusingeditorslikeVSCodetosavefilesinUTF-8format,especiallywhenhandlingnon-ASCIIcharacters.

Using XML as a Data Source in modern applications Using XML as a Data Source in modern applications Sep 03, 2025 am 06:18 AM

XMLremainsrelevantinmodernapplicationswhenintegratingwithenterprisesystems,handlingdocument-centricdata,managingconfigurationinframeworks,andensuringdataintegrityviastrictschemas;1.UseefficientparserslikeSAXorStAXtohandlelargeXMLfileswithoutexcessive

Why and When to Use XML Namespaces Why and When to Use XML Namespaces Sep 23, 2025 am 03:34 AM

XMLnamespacesareusedtopreventnamecollisionswhencombiningdifferentXMLvocabulariesinasingledocument.1)TheyavoidnameconflictsbyuniquelyidentifyingelementswiththesamelocalnamebutdifferentcontextsusingdistinctnamespaceURIs,asseenwithbook:titleandemp:title

Related articles