← Prev in month ← Prev in thread

How to get Node value In a DOM Tree

From
Seetha Rama Krishna <>
To
Date
2006-05-31T13:52:03Z
ID
<>
Thread
How to get Node value In a DOM Tree
Hello Techies,
I am trying to create a DOM Tree. I had create Node's for the DOM Tree. I want to know how to set the Values to these Nodes.

Element root = null;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.newDocument();
root = document.createElement(Root_Element);
document.appendChild(root);
Element applicationElement =document.createElement(Application_Element);
           applicationElement.setNodeValue("krish");
  root.appendChild(applicationElement);
 




Now when I try to get the This Node Value , I am getting null Pointer Exception.
Here is my code of retrieving the node value

NodeList applicationNodeList = null;
 applicationNodeList =finalElement.getElementsByTagName("application");
 System.out.println("applicationNodeList size"+applicationNodeList.getLength());
 
     for(int i = 0; i<= applicationNodeList.getLength();i++)
     {
         System.out.println("eachApplicaiton in the DOM"+applicationNodeList.item(i).getNodeValue());
             
         }



I am getting NodeList size is 1 , but I the node Value I am getting as Null.


What I am doing for setting the Node Value is correct(or) am I missing some thing.
Can u guys help me out to fix this problem.




regards,
ramu


Yahoo! India Answers: Share what you know. Learn something new Click here
Send free SMS to your Friends on Mobile from your Yahoo! Messenger Download now
← Prev in month ← Prev in thread