This article mainly introduces JavaScript to obtain XML data methods, the need for friends can refer to the following
Hot.xml file: code as follows: <?xml version= "1.0" encoding= "gb2312"?> <root> <item> <name> Yifei </name> <url>MingXing/LiuYiFei.htm</url> <color>red< /color> </item> <item> <name> jolin </name> <url>mingxing/ caiyilin.htm</url> <color>blue</color> </item> <item> < name> Zhangnala </name> <url>MingXing/ZhangNaLa.htm</url> <color>green</color > </item> <item> <name> Angela Culvert </name> <url>mingxiang/ zhangshaohan.htm</url> <color>grey</color> </item> <item> <name> Jane Zhang </name> <url>MingXing/ZhangLiangYin.htm</url> <color>black </color> </item> <item> <name> shrieked spring </name> <url>mingxing/liyuchun.htm</url> <color>yellow</color> </item> <item> <name> Vivian Hsu </name> <url>MingXing/XuLuXuan.htm</url> <color>pink</ color> </item> </root> demo1.html file: <html xmlns= "http:// Www.w3.org/1999/xhtml "> <head> <meta http-equiv=" Content-type "content=" text/html; charset=gb2312 "/> <title>javascript get XML data </title> <script language=" JavaScript " > Code as follows: Var xmldoc=new activexobject ("Microsoft.XMLDOM"); Create XMLDOM objects xmldoc.async=true; Using the asynchronous Load xmldoc.onreadystatechange=loadedsales; function loadedsales () { var txt= ""; if (xmldoc.readystate = 0) { alert ("0"); } if (xmldoc.readystate = = 1) { alert ("1"); } if (xmldoc.readystate = 2) { alert ("2"); } if (xmldoc.readystate = = 3) { alert ("3"); } if (xmldoc.readystate = 4) { if (xmlDoc.parseError.errorCode!= 0) { txt=" XML Parse Error! "; }else{ var items=xmldoc.documentelement.selectnodes (" item "); if (items!= null && Items.length > 0) { for (var i=0 i < items.length; i++) { txt + "<li><a href=" +ite ms[i].childnodes[1].text+ "mce_href=" +items[i].childnodes[1].text+ "style=" color: "mce_style=" color: "" +items[i. childnodes[2].text+ ">" +items[i].childnodes[0].text+ "</a></li>"; } }else{ txt= ""; } } }else{ txt= ""; } ("Sales") document.getElementById} function Loadxmldoc () { var url= "Hot.xml"; xmldoc.load (URL); } </script> </head> <body onload= "Loadxmldoc ()" > <div id= "Sales" ></div> </body> </html>