This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
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


Win a copy of Building Microservices this week in the Design forum!
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
Sheriff

Joined: Oct 14, 2005
Posts: 19728
    
  10

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 .
 
Have you checked out Aspose?
 
subject: Need help in replacing a node value
 
It's not a secret anymore!