HTML如何 获取XML的元素里的嵌套的元素的数据。
<html>
<body>
<xml id= "cdcat " src= "test.xml ">
</xml>
<table datasrc= "#cdcat ">
<tr >
<td style= "color:red; "> <span datafld= "TITLE "> </span> </td>
<td> <span datafld= "ARTIST "> </span> </td>
<td> <span datafld= "PRICE "> </span> </td>
<td> <span datafld= "TT1 "> </span> </td>
<tr>
</table>
</body> </html>
--------------
TEST.XML
<?xml version= "1.0 " encoding= "ISO-8859-1 "?>
<CATALOG>
<CD>
<TITLE> Empire Burlesque </TITLE>
<ARTIST> Bob Dylan </ARTIST>
<COUNTRY> USA </COUNTRY>
<COMPANY> Columbia </COMPANY>
<PRICE> 10.90 </PRICE>
<year> <TT1> 1985 </TT1>
</year>
</CD>
<CD>
<TITLE> Hide your heart </TITLE>
<ARTIST> Bonnie Tyler </ARTIST>
<COUNTRY> UK </COUNTRY>
<COMPANY> CBS Records </COMPANY>
<PRICE> 9.90 </PRICE>
<year> <TT1> 1988 </TT1>
</year>
</CD>
</CATALOG>
-----------------
HTML如何 获取XML的 <TT1> 的数据。
上面的不能获取到。
[解决办法]
nodes = cdcat.XMLDocument.selectNodes( "//TT1 ");
for(i =0;i <nodes.length;i++)
alert(nodes[i].text)
[解决办法]
用Xpath去匹配吧
[解决办法]
var x=xmlDoc.getElementsByTagName("CD");
for (i=0;i<x.length;i++)
{
temp=x[i].getElementsByTagName("year")[0].childNodes[0].nodeValue);
}