|
Re: [xml-dev] How to get Node value In a DOM Tree
|
[
Lists Home |
Date Index |
Thread Index
]
- To: Chris Burdess <dog@bluezoo.org>
- Subject: Re: [xml-dev] How to get Node value In a DOM Tree
- From: Seetha Rama Krishna <ram_kurra@yahoo.co.in>
- Date: Wed, 31 May 2006 15:29:02 +0100 (BST)
- Cc: xml-dev@lists.xml.org
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.co.in; h=Message-ID:Received:Date:From:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=RWhV+XFhqoaxN8DVO2s48iQbR+bFv/vDSaMehkJGT0wiGAzjdLxJelPB4U4t+ZmAdocPRe7xlaDq6Po/CXt1QeotHUbjh69hHQ53tuyaWkGXzOXjaIPuna3xhTKPyLlbMyC2ivwblVqlKdM66gPWN1iiMUSSo6dnUp54J+Xjmbc= ;
- In-reply-to: <3400AC2C-18A7-42DA-A7B9-39D287F830B9@bluezoo.org>
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 <dog@bluezoo.org> 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
|
|
|
|
|