File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes dom (getNodeValue) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "dom (getNodeValue)" Watch "dom (getNodeValue)" New topic
Author

dom (getNodeValue)

Liza Boa
Greenhorn

Joined: Aug 16, 2001
Posts: 23
hi
how can I get the content of a tag (for ex. the String "name")
<login>name</login>
? I have the tags stored in a NodeList "loginList", built with
document.getElementsByTagName("login").
While
loginList.item(int i).getNodeName() works fine and returns "login",
loginList.item(inti).getNodeValue() returns null.
Can somebody help me?
Kapil Sabharwal
Greenhorn

Joined: Sep 26, 2001
Posts: 4
Liza
I think the problem with your approach is that you are not accesing the Node.TEXT_NODE here, instead u are using Node.ELEMENT_NODE which in this case is <login>. Try this out when u get the NodeList "loginList":
NodeList child = loginList.item(0).getChildNodes();
//this is going to be the TEXT Node
Node text = child.item(0);
String xyz = text.getNodeValue();
Kapil

Originally posted by Liza Boa:
hi
how can I get the content of a tag (for ex. the String "name")
<login>name</login>
? I have the tags stored in a NodeList "loginList", built with
document.getElementsByTagName("login").
While
loginList.item(int i).getNodeName() works fine and returns "login",
loginList.item(inti).getNodeValue() returns null.
Can somebody help me?

Liza Boa
Greenhorn

Joined: Aug 16, 2001
Posts: 23
Thank you, Kapil!
best regards, Liza
Palani kumar
Greenhorn

Joined: Sep 01, 2001
Posts: 12
if you have to get the value for "name"
you can do so like this
document.getElementByTagName("login").item(0).getFirstChild().getNodeValue();
Cheers
Palanikumar


In the end everything is Right,If it's not then It's not the End
Palani kumar
Greenhorn

Joined: Sep 01, 2001
Posts: 12
if you have to get the value for "name"
you can do so like this
document.getElementByTagName("login").item(0).getFirstChild().getNodeValue();
Cheers
Palanikumar
------------------
In the end everything is Right,If it's not then It's not the End
Will Rogers
Greenhorn

Joined: Dec 21, 2001
Posts: 4
I was having the same problem (getNodeValue returning null), so I tried the
nodelist.item(0).getFirstChild().getNodeValue()
method and now it's throwing NullPointerExceptions
my xml struct looks like this:
<root>
...<element attr="true">
......<subelement>data</subelement>
......<subelement2>data</subelement2>
...</element>
...<element attr="true">
......<subelement>data</subelement>
......<subelement2>data</subelement2>
...</element>
...<differentelement attr="spam">
......<subelement>data</subelement>
...</differentelement>
</root>
the tags have been changed to protect the innocent. . can anybody help with this?
the net of what I'm doing is this:
doc.getElementsByTagName().item(0).getChildNodes().item(0).getFirstChild().getNodeValue()
Am I digging too deep in this case?
thanks for your help


<a href="http://www.rusmo.com" target="_blank" rel="nofollow">www.rusmo.com</a>
TimB
Greenhorn

Joined: Sep 13, 2002
Posts: 3
Ok, I am having a simmilar issue, I have a Node:
<MS attribute="bla bla bla">This is my message</ms>
I am trying to get both the attribute and the value of the node. I have no problems getting the attributes the problem I am having is getting the node value. I am using:
message.getNodeValue();
Where the node name is message. This is giveing me a null value back. Any suggestions?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: dom (getNodeValue)
 
Similar Threads
Help parse using JAXP
req.isUserInRole("admin"); return false??
getNodeValue() returing null WHY?
Navigating with form actions in Struts
help with web service to display xml file contents using netbeans