JS in the browser parsing XML, support IE, Firefox, Chrome, etc.

Source: Internet
Author: User

JS loaded in Chrome XML,JS load XML support Ff,ie6+,opera and other browsers

See Code:

<!DOCTYPE HTML><HTMLLang= "en"><Head>    <MetaCharSet= "UTF-8">    <title>JS in the browser parsing XML, support IE, Firefox, Chrome, etc.</title></Head><Body>    <Script>        functionLoadxmldoc (file) {Try{                //IExmldoc=NewActiveXObject ("Microsoft.XMLDOM"); }Catch(e) {////firefox, Mozilla, Opera, etcxmldoc=Document.implementation.createDocument ("","",NULL); }            Try{Xmldoc.async=false; Xmldoc.load (file);//Chrome has no Load method            }Catch(e) {//for Chrome, but only via HTTP, access via file protocol will be an error                varXMLHTTP= Newwindow.                  XMLHttpRequest (); Xmlhttp.open ("GET", file,false); Xmlhttp.send (NULL); XmlDoc=xmlhttp.responseXML.documentElement; }            returnxmldoc; }        varob=Loadxmldoc ("Stu.xml"); varStu=Ob.getelementsbytagname ("Stu");  for(varI=0; I<Stu.length;i++){            varData=Stu[i].childnodes;  for(varJ=0; J<data.length;j++){                if(Data[j].nodetype==1){                    if(document.all) document.write (Data[j].text+" ");//IE                    Elsedocument.write (data[j].textcontent+" "); }} document.write ("<br/>"); }    </Script></Body></HTML>

Attached Stu.xml

<?XML version= "1.0" encoding= "UTF-8"?><stulist>    <Stu>        <name>Tom</name>        < Age>20</ Age>        <Sex>Man</Sex>        <ClassID>Lamp87</ClassID>    </Stu>    <Stu>        <name>John doe</name>        < Age>22</ Age>        <Sex>Woman</Sex>        <ClassID>Lamp86</ClassID>    </Stu>    <Stu>        <name>Harry</name>        < Age>21st</ Age>        <Sex>Woman</Sex>        <ClassID>Lamp87</ClassID>    </Stu>     <Stu>        <name>Harry</name>        < Age>21st</ Age>        <Sex>Woman</Sex>        <ClassID>Lamp87</ClassID>    </Stu>    <Stu>        <name>Zhao Liu</name>        < Age>24</ Age>        <Sex>Man</Sex>        <ClassID>Lamp88</ClassID>    </Stu></stulist>

Feel good, recommend Oh!

JS in the browser parsing XML, support IE, Firefox, Chrome, etc.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.