• Post Reply Bookmark Topic Watch Topic
  • New Topic

JAXP query  RSS feed

 
Ambika Jain
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am new to JAXP.
Why do we have to use getFirstChild() method to get the value of the element node, as below :

if (child.getNodeType() == child.TEXT_NODE){
System.out.println("Text: "+child.getNodeValue());
} else if (child.getNodeType() == child.ELEMENT_NODE) {
System.out.println(child.getNodeName()+" = "+
child.getFirstChild().getNodeValue());
} if (child.getNodeType() == child.TEXT_NODE){

Thanks.
 
William Barnes
Ranch Hand
Posts: 1049
2
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks to me that you are using the name of the "first" child node for the node you are on (the node you are on is represented by the variable "child")

A node can have one or more subnodes, aka "children". If a node has no subnodes it is a "leaf". The methods on a node include "give me the first child", "give me the last child", "give me the next child", ...
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!