aspose file tools*
The moose likes XML and Related Technologies and the fly likes Need help in replacing a node value 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 "Need help in replacing a node value" Watch "Need help in replacing a node value" New topic
Author

Need help in replacing a node value

Preetish Panda
Greenhorn

Joined: May 10, 2010
Posts: 9
I'm trying to parse XML file in order to update a node value

<abc>
<def>/home/setup</def>
<fgh>encrypted</fgh>
<hij>configuser</hij>
</abc>

I need to update node value of <fgh>

Here is my code .. I'm able to read node value .. but can't update it.Because, for some reason setNodevalue is not working.
Any help is highly appreciated.

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18993
    
    8

You have committed the common beginner error of assuming that an Element's value is the text in it's only child node. It isn't. Read the API documentation for Node to find out what an Element's value actually is.

And then consider that an Element can have more than one child (as does the <abc> element in your example). If you want to change any of its child nodes (and you do want that) then you will either have to change them, if possible, or create new ones to replace the existing ones.
Preetish Panda
Greenhorn

Joined: May 10, 2010
Posts: 9
I resolved it using jdom and inbuilt SAXBuilder class .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need help in replacing a node value