Meaningless Drivel is fun!*
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "DOM API don Watch "DOM API don New topic
Author

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...
thanks
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    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