Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DOM API don't undestand

 
jazy smith
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
thanks
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
    Posts: 101
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    thanks a lot Paul
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic