Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

DOM API don't undestand

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 27288
87
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    thanks a lot Paul
     
    Consider Paul's rocket mass heater.
    reply
      Bookmark Topic Watch Topic
    • New Topic