This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
My requirement is... i have an xml file. In which i need to set the value for a tag.
Please refer to the xml file .My requirement is , say for example...in the attached xml,
book tag is repeating. First i need to see which book is having the attribute 'id' as bk102. And then i need to find whether the value of title is "Midnight Rain". If its Midnight Rain then i need to update the value of "price" tag to 10. Currently it is 5.95..i need to change this to 10.
Can someone tell me which would be the best approach to do this.
What have you tried so far? How are you parsing the XML?
Joined: Oct 06, 2008
I am using javax.xml.parsers.DocumentBuilder to read the xml file and using org.w3c.dom.Document for parsing the file. I could read the values of the tag , attributes using NodeList. But i am not sure how to set the value for the tag. I tried using setNodeValue for setting the value for the tag. But its not updating the value.
Alternatively you can create a org.w3c.dom.Text element by calling Document's createTextNode method. You can then call appendChild on the node to add it. You may want to remove all other children first: