• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Replace value of XML element using API

 
Ranch Hand
Posts: 281
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
reply
    Bookmark Topic Watch Topic
  • New Topic