This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes DOM API don't undestand Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "DOM API don Watch "DOM API don New topic

DOM API don't undestand

jazy smith
Ranch Hand

Joined: Nov 18, 2009
Posts: 101
Hi all,

I have a piece of simple xml document.

Now I have JAX API

the result it returns is 1. I don't understand why. How does it calculate the length ?

next question, for the same xml file,

the result is 7. How come ? I was thinking the child elements of "student" is 3 (name, rollno, address) it should return 3. how come it returned 7.
please explain me as I have been trying to draw the schematic diagram and tried my best to undestand but couldn't get through...
Paul Clapham

Joined: Oct 14, 2005
Posts: 18541

You're asking how it calculates the "length" of a NodeList? That would be the number of the elements in the NodeList.

In your example you found a NodeList containing all of the <student> elements in your document. There's only one such element. Therefore the NodeList contains just one element. So it shouldn't be a surprise that the "length" of the NodeList is one.

As for the child nodes of that one <student> element, they are:
  • A whitespace text node
  • A <name> element
  • A whitespace text node
  • A <rollno> element
  • A whitespace text node
  • An <address> element
  • A whitespace text node

  • You'll find that's 7 children.
    jazy smith
    Ranch Hand

    Joined: Nov 18, 2009
    Posts: 101
    thanks a lot Paul
    wood burning stoves
    subject: DOM API don't undestand
    Similar Threads
    reading/updating child node attribute in xml String
    help with web service to display xml file contents using netbeans
    parsing XML in java
    Extract full path when parsing XML
    reading xml document by parsing