Get length of the Xml provided
I am trying load the XML
<Node>
<Subnode a = "1" b = "2" />
<Subnode a = "4" b开发者_运维技巧 = "5" />
</Node>
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.loadXML("c:\\test.xml");
var length = xmlDoc.childNodes.length
but length is Zero which is incorrect
The Subnodes are children of the documentElement; try
xmlDoc.documentElement.childNodes.length
The method to load a file is .load (not .loadXML).
From what I see this line is incorrect.
xmlDoc.loadXML("c:\\test.xml");
It should be
xmlDoc.load("c:\\test.xml");
See API document for the difference between load and loadXML.
Also it's useful to check for errors, using the parseError property, after calling any of the load methods. Something along these lines:
if (xmlDoc.parseError.errorCode != 0) {
// Handle error
}
In addition, as indicated in the comments, the async property should be false
not "false".
精彩评论