• 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

How to modify the XML Document?

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to modify the XML Document?

I want to modify the data values present in the XML.

For Example the XML file is :

<student>
<student-name>venu</student-name>
<student-number>786</student-number>
</student>

Here I want to modify student-name and student-number values.

Actually my XML is not this simple.

I am able to get the values for the particular node by using XPath.

Like this:

String studentName = (String) xPath.evaluate(studentNamePath,xmlDocument,XPathConstants.STRING);

But how to modify the same node values?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assuming that "xmlDocument" is an instance of org.w3c.dom.Document, then the DOM API would probably be easiest. Here are some DOM example codes; particularly e545 is relevant.
 
All of life is a contant education - Eleanor Roosevelt. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic