Javascript显示根XML文件中有多少个元素

时间:2015-11-02 00:05:35

标签: javascript html xml

我需要这个html / javascript文件来显示XML文档直接位于根元素下的多个元素。

这应显示为:

toOf()

相反,它显示为:

The root element has this many direct children: 2

我该怎么做?

这是我正在使用的代码:

The root element has this many direct children: 0The root element has this many direct children: 1 

1 个答案:

答案 0 :(得分:1)

你的脚本应该是

var xmlDoc = loadXMLDoc("XML65.xml");
document.write("The root element has this many direct children: " + xmlDoc.childNodes.length);

P.S。我强烈建议您熟悉document.write

的替代方法