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

How to modify a nested XML element using Java

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: 5620

Re: How to modify a nested XML element using Java

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/java_dom_parse_document.htm

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

Return to “General XML Questions”

Who is online

Users browsing this forum: No registered users and 1 guest