Hi all, My xml file looks like this. <program> <client host="192.168.1.34"> </client> </program> I want to update the value of host attribute to 192.168.1.66.How to do this in java.I have tried using DOM but it is not working.Can somebody have any idea?
Note that after modifying the attribute you have to write the entire DOM back out to the file. Bill
Joined: May 06, 2005
Thanks William, You are correct.I think I am not writing back the dom structure.How should I do this.Which API should I use for this? with regards, ajse
Author and all-around good cowpoke
Joined: Mar 22, 2000
If you have Java 1.4 or 1.5 you will be using the javax.xml.transform.Transformer class and related classes. Here is an example, where baos is an instance variable:
Instead of the ByteArrayOutputStream this could be writing to a FileOutputStream. The newTransformer() call creates a Transformer that does not change the DOM, other Transformers can apply a XSL transformation.
Welcome to the weird world of XML with Java - Sun has a pretty good tutorial, just google for "Sun XML tutorial"