Next in thread →
Next in month →
Re: [xml-dev] How to get Node value In a DOM Tree
Hi Chris,
Thanks for u r reply. I used getNodeType() to get the Node Type . It is giving 1. i.e it Element Node.
Then How can I retrieve the value of Element Node.
regards,
Ramu.
Chris Burdess <[email protected]> wrote:
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
Thanks for u r reply. I used getNodeType() to get the Node Type . It is giving 1. i.e it Element Node.
Then How can I retrieve the value of Element Node.
regards,
Ramu.
Chris Burdess <[email protected]> wrote:
Seetha Rama Krishna wrote:
> 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.
http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#ID-1950641247
"In cases where there is no obvious mapping of these attributes for a
specific nodeType (e.g., nodeValue for an Element or attributes for a
Comment), this returns null."
Probably you want a Text node. Read the DOM specification.
--
ç¬ Chris Burdess
"They that can give up essential liberty to obtain a little safety
deserve neither liberty nor safety." - Benjamin Franklin
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
Next in thread →
Next in month →