开发者

what are DocumentElement's children?

开发者 https://www.devze.com 2023-01-26 07:08 出处:网络
I have a simple XML file as shown below. <?xml version=\"1.0\" encoding=\"UTF-8\"?&开发者_如何学运维gt;

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

--Vaman


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

0

精彩评论

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