开发者

Get length of the Xml provided

开发者 https://www.devze.com 2023-03-26 07:58 出处:网络
I am trying load the XML <Node> <Subnode a = \"1\" b = \"2\" /> <Subnode a = \"4\" b开发者_运维技巧 = \"5\" />

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".

0

精彩评论

暂无评论...
验证码 换一张
取 消