How to modify a nested XML element using Java

Questions about XML that are not covered by the other forums should go here.
Sweg
Posts: 1
Joined: Tue Jul 03, 2018 2:28 pm

How to modify a nested XML element using Java

Post by Sweg » Tue Jul 03, 2018 2:33 pm

I have an XML file stored in src/test/resources.

I am trying to do the following:

1. Retrieve the XML Body
2. Modify a nested element within the body
3. Convert the XML body to a string

Below is a sample XML:

Code: Select all


<Client>
<Name>
</Name>
<Location>
<Address>
<Line1>Test Address<Line1>
</Address>
</Location>
</Client>
So I want to change Client.Location.Address.Line1 within my java method, & then convert that entire XML to a string. But, I don't want to overwrite the original XML.

Can this be done?

Radu
Posts: 6388
Joined: Fri Jul 09, 2004 5:18 pm

Re: How to modify a nested XML element using Java

Post by Radu » Tue Jul 03, 2018 2:45 pm

Hi,

This forum is for posting questions related to Oxygen XML Editor.
The Java runtime environment contains a DOM API which allows you to parse XML as a structure of nodes and to modify it:

http://www.tutorialspoint.com/java_xml/ ... cument.htm

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

Post Reply