[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: How to get Node value In a DOM Tree

  • To: Chris Burdess <dog@b...>
  • Subject: Re: How to get Node value In a DOM Tree
  • From: Seetha Rama Krishna <ram_kurra@y...>
  • Date: Wed, 31 May 2006 15:29:02 +0100 (BST)
  • Cc: xml-dev@l...
  • 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@b...>

get node value
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@b...> 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 http://us.rd.yahoo.com/mail/in/mailanswersshare/*http://in.answers.yahoo.com/
Send free SMS to your Friends on Mobile from your Yahoo! Messenger http://us.rd.yahoo.com/mail/in/freesms/*http://messenger.yahoo.com/download.php

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.