• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Confusion in JAXP DOM parser

 
Ranch Hand
Posts: 395
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all.
I just found out out thie interesting confusion. I don;t know i am write or wrong, but can anyone explain this concept of "Siblings".
If i have xml file like this:
</GrandParent>
<Parent1>
<Child1>
name1
</Child1>
<Child2>
name2
</Child2>
</Parent1>
<Parent2>
<Child3>
name3
</Child3>
<Child4>
name4
</Child4>
</Parent2>
</GrandParent>
When i am using JAXP DOM parser, and my node is poiting to "Child1" of "Parent1", and i use node.getNextSibling() points me to "name1", not to "Child2"
Isn't it confusing.
Isn't "name1" is child of "Child1"
Can anyone explain this concept.
TIA
L Goundalkar.

------------------
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Javadocs say that getNextSibling returns "The node immediately following this node." - So your result is not what I expected either.
BBill
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to the DOM spec, the content of a node is considered another node. If the contents issimple text-data( as in your examle), it becomes a "text node". Text nodes have no child nodes.
So, name1 is a child node of child1 and is of type text node.
HTH
------------------
Ajith Kallambella M.
Sun Certified Programmer for the Java�2 Platform.
IBM Certified Developer - XML and Related Technologies, V1.
 
L Goundalkar
Ranch Hand
Posts: 395
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi..
Ajith thats right. But do you agree isn;t this API more confusing and difficult to use. Also as i mentioned in the other thread, getNextSibling() and getPreviousSibling() functions doesn't follow the same rule.
Is it a Bug in Java API ???

------------------
L Goundalkar
lggoundalkar@hotmail.com
Sun Certified Programmer for Java 2 Platform
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
API is fine but the documentation sucks.
 
L Goundalkar
Ranch Hand
Posts: 395
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ajith, I don't completely agree with you.
The API is also wrong.Don't you think so??

------------------
L Goundalkar
lggoundalkar@hotmail.com
Sun Certified Programmer for Java 2 Platform
 
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Use Jdom, you won't regret it.
 
incandescent light gives off an efficient form of heat. You must be THIS smart to ride this ride. Tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!