关于JavaScript解析XML的问题,请各位指点一下
这是我的XML结构
<?xml version="1.0" encoding="GB2312"?>
<tclass tclassname="计算机类">
<row>
<ttypecode>07001</ttypecode>
<ttypename>网络类</ttypename>
</row>
<row>
<ttypecode>07002</ttypecode>
<ttypename>数据库类</ttypename>
</row>
<row>
<ttypecode>07003</ttypecode>
<ttypename>操作系统类</ttypename>
</row>
</tclass>
这是我定义的JavaScript的FUN
function loadbook(tclassName,ttypeName) {
var tclassobj = document.all(tclassName);
var ttypeobj = document.all(ttypeName);
var xmlhttp = document.all("xmlobj");
ttypeobj.options.length = 0;
var file = tclassobj.options[tclassobj.selectedIndex].value;
xmlhttp.async = false;
xmlhttp.load(file);
var Vttype = xmlhttp.selectNodes("tclass/row");
var idx,name,idValue;
//运行到这时我的Vttype.length值为3这是对的,但我如何取得ttypecode 和 ttypename的值
for(idx = 0; idx < Vttype.length; idx ++) {
name = Vttype[idx].getAttribute("ttypename"); //这样写不对,取出来为null
idValue = Vttype[idx].getAttribute("ttypecode");//这样写不对,取出来为null
ttypeobj.options.length++;
ttypeobj.options[ttypeobj.options.length - 1].value = idValue;
ttypeobj.options[ttypeobj.options.length - 1].text = name;
}
}