我有以下XML文件,我可以使用
获取非嵌套值xmlHttp.responseXML.getElementsByTagName('bio_fname')[0].firstChild.nodeValue
我希望得到嵌套值类似于每个循环的东西这可能吗? 感谢
<bio>
<bio_exists>True</bio_exists>
<bio_fname>Test</bio_fname>
<bio_lname>Tester</bio_lname>
<bio_pos>
<pos>
<name>White Collar</name>
<company>Foo</company>
<rank>1</rank>
</pos>
<pos>
<name>Blue Collar</name>
<company>BAR</company>
<rank>2</rank>
</pos>
</bio_pos>
</bio>
答案 0 :(得分:1)
var nodes = xmlDoc.selectNodes("/bio/biopos");
var ids = [],names = [] , designations = [];
for ( var i = 0; i < nodes.length; i++)
{
ids.push(nodes[i].selectSingleNode("name").firstChild.nodeValue);
names.push(nodes[i].selectSingleNode("company").firstChild.nodeValue);
designations.push(nodes[i].selectSingleNode("rank").firstChild.nodeValue);
}