I have a simple XML file as shown below.
<?xml version="1.0" encoding="UTF-8"?&开发者_如何学运维gt;
<myConfig>
<datasets>
<dataset name="set1">
<var name="orgName">org1</var>
</dataset>
</datasets>
</myConfig>
When I print the size of the DocumentElement's children it shows me 3. I was expecting only one: <datasets>. Which are the other two children of DocumentElement?
Thanks in advance
--VamanA text node containing \n
and the indent, <dataset>
element, another text node. Update the last text node contains \n
only.
I'm guessing the other two children are dataset and var. In other words - the count is recursive. So you have A -> B -> C -> D : D, C, are both children of A as well as B.
One way to confirm this: write a for loop that goes through each child and prints out the element name.
This is probably specific to the xml parser though. If you called a similar method with a different xml parser, there is a good chance you could get a different number. Some might return 1, some might return 4 (one for the text node containing "org1").
精彩评论