请教xml读取节点的问题!
xml代码如下:
<?xml version= "1.0 " encoding= "gb2312 " ?>
- <news>
- <xyyw>
<title> ·47 </title>
<title> ·48 </title>
</xyyw>
- <xyzt>
<title> ·46 </title>
<title> ·45 </title>
</xyzt>
- <gcsy>
<title> ·43 </title>
<title> ·42 </title>
<title> ·41 </title>
</gcsy>
</news>
请问用javascript如何读取 <xyzt> 这些节点的 <title> !显示出来并且加上连接~
[解决办法]
var oDoc = new ActiveXObject( "Msxml2.DOMDocument ");
var s = " ";
oDoc.async = false;
oDoc.load( "my.xml ");
if(oDoc.parseError.errorCode != 0){
alert(oDoc.parseError.reason);
}
else{
oNodes = oDoc.selectNodes( "/news/xyzt/title ");
for(var i=0;i <oNodes.length;i++){
s += " <a href=\ "xxxxx.xxx?id= " + escape(oNodes[i].text) + "\ "> " + oNodes[i].text + " </a> <br/> \n ";
}
}
alert(s);