Originally posted by Sam Gehouse:
I want to replace value of an XML element. What is the fastest way of doing it? I would like to use SAX parsing.
e.g.,
<name>xyz</name>
I want to use API to read the XML and then replace the value "xyz" with "abc" so that the xml looks like:
<name>abc</name>
I have efficient algorithm to parse xml and get values in name-value pair. I can also manually re-create xml using those name-value pairs and update the required value. But I do not want to write code to replace the value.
I would like to use an existing API for replacing the value.
What API can I use to make it happen, instead of stitching them together by coding myself using the name-value pairs in memory?
I am sure this would not be the fastest way around, but its one of the easiest and more maintainable way I can think of.
Parse the XML and create a DOM document.
Use Xpath to get the Node's you want to update
update the Nodes and serialize the Document again
-Rajagopal