Click here to Skip to main content
15,922,894 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the following xml file "User.xml"
XML
<pre><users>
    <user>
        <name>some</name
    </user>
    <user>
        <name>any</name>
    </user>
</users></pre>

In the code I do this
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc= db.parse("User.xml");
Element root = doc.getDocumentElement();
NodeList nodes = root.getChildNodes();
System.out.println(nodes.getLength());

it prints 5 not 2 .Why??
the nodes'type are : text element text element text
Posted
Updated 16-Apr-10 0:20am
v2

1 solution

There are 3 text nodes (containing just newlines):
XML
<pre><users>
    (text node '\n' here)
    <user>
        <name>some</name>
    </user>
    (text node '\n' here)
    <user>
        <name>any</name>
    </user>
    (text node '\n' here)
</users></pre>

:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900