Hot. xml file:
Copy codeThe Code is as follows:
<? Xml version = "1.0" encoding = "gb2312"?>
<Root>
<Item>
<Name> Liu Yifei </name>
<Url> MingXing/LiuYiFei.htm </url>
<Color> red </color>
</Item>
<Item>
<Name> Cai Yilin </name>
<Url> MingXing/CaiYiLin.htm </url>
<Color> blue </color>
</Item>
<Item>
<Name> Zhang Nana </name>
<Url> MingXing/ZhangNaLa.htm </url>
<Color> green </color>
</Item>
<Item>
<Name> Zhang Shaohan </name>
<Url> MingXiang/ZhangShaoHan.htm </url>
<Color> gray </color>
</Item>
<Item>
<Name> Zhang Liangying </name>
<Url> MingXing/ZhangLiangYin.htm </url>
<Color> black </color>
</Item>
<Item>
<Name> Li Yuchun </name>
<Url> MingXing/LiYuChun.htm </url>
<Color> yellow </color>
</Item>
<Item>
<Name> Xu ruoyun </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> retrieve XML data using JavaScript </title>
<Script language = "javascript">
Copy codeThe Code is as follows:
Var xmlDoc = new ActiveXObject ("Microsoft. XMLDOM"); // create an XmlDom object
XmlDoc. async = true; // use asynchronous loading
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 parsing error! ";
} Else {
Var itemsdetail xmldoc.doc umentElement. selectNodes ("item ");
If (items! = Null & items. length> 0)
{
For (var I = 0; I <items. length; I ++)
{
Txt + = "<li> <a href =" + items [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 = "";
}
Document. getElementById ("sales"). innerHTML = txt;
}
Function loadXmlDoc ()
{
Var url = "Hot. xml ";
XmlDoc. load (url );
}
</Script>
</Head>
<Body onLoad = "loadXmlDoc ()">
<Div id = "sales"> </div>
</Body>
</Html>
: