JavaScript implementation method of loading XML file _javascript tips

Source: Internet
Author: User

The example in this article describes the way JavaScript loads an XML file. Share to everyone for your reference, specific as follows:

XML file Var uRl that needs to be read = "Jsreadxml.xml";
var xmldoc; Initialize to assign the above defined variable/function showcurcity () {if window.
ActiveXObject) {xmldoc=new ActiveXObject ("Microsoft.XMLDOM"); xmldoc.async= "false" Xmldoc.load (uRl); GetValue ();} else if (document.implementation && document.implementation.createDocument) {xmldoc=
Document.implementation.createDocument ("", "root", null);
Xmldoc.load (URL);
Xmldoc.onload=getvalueff; }/else {//return null;//}//} function GetValue () {var nodes=xmldoc.documentelement.childnodes; var now=new Date (
); for (i=0;i<nodes.length;i++) {var value=nodes.item (i). Childnodes.item (0). Text; alert (Nodes.item (i).
Childnodes.item (1). text);
Alert (Nodes.item (i). Childnodes.item (2). text); The function Getvalueff () {var ccode=xmldoc.getelementsbytagname ("date"); var now = new Date (); var Nowvalue=now.getfullye
AR () + ' year ' + (Now.getmonth () +1) + ' month ' +now.getdate () + ' Day '; for (i=0;i<ccode.length;i++) {alert (Xmldoc.getelementsbytagname ("imgsrc") [I].childnodes[0].nodevalue); Alert (Xmldoc.getelementsbytagname ("title") [I].childnodes[0].nodevalue);
Alert (xmldoc.getelementsbytagname ("url") [I].childnodes[0].nodevalue);

 }
}

I hope this article will help you with your JavaScript programming.

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.