这个xml为什么javascript解释不了?急!!!!邪门了得到总是空值?
<Department>
<Table>
<dep_id> 15 </dep_id>
<dep_name> 财务部门 </dep_name>
</Table>
<Table>
<dep_id> 20 </dep_id>
<dep_name> 财务部门1 </dep_name>
</Table>
</Department>
javascript 语句:
var oDoc = new ActiveXObject( "MSXML2.DOMDocument ");
oDoc.loadXML(result);
items = oDoc.selectNodes( "//Department/Table ");
for (var item = items.nextNode(); item; item = items.nextNode()){
var dep_id = item.selectSingleNode( "dep_id ").nodeTypedValue;
var dep_name = item.selectSingleNode( "dep_name ").nodeTypedValue;
var newOption = document.createElement( "OPTION ");
newOption.text = dep_name;
newOption.value = dep_id;
}
------解决方案--------------------var oDoc = new ActiveXObject( "MSXML2.DOMDocument ");
oDoc.async = false;
oDoc.loadXML(result);
items = oDoc.selectNodes( "//Table ");
for(var i = 0; i < items.length; i++)
{
var dep_id = items[i].childNodes[0].text;
var dep_name= items[i].childNodes[1].text;
}
或者
for(var i = 0; i < items.length; i++)
{
var dep_id = items[i].selectSingleNode( "dep_id ").text
var dep_name= items[i].selectSingleNode( "dep_name ").text
}
我还是第一次帮人回答问题,呵呵,给点分吧