0

I have an XML document in a foreign language and another XML document in English. I am trying to replace some nodes in the foreign document with nodes from the English document and export the document.

I have been working on this for days now and have tried countless things form importing both documents into text with a Scanner, BufferedReader, etc. with no good results.

I'm at a loss on what else I can try. I have searched for days and have nothing. Maybe what I'm trying to do cannot be done although it seems simple enough. Any help/direction would be appreciated.

Droid
  • 65
  • 1
  • 9

2 Answers2

2

Put them into DOM objects, then use XPATH to locate and select nodes, to copy values between them.

M21B8
  • 1,867
  • 10
  • 20
0

Depending on what you need to replace and what you mean by "export", I would use an XML parser like SAX using the following algorithm

For each node that you read
    Replace attributes or text as necessary
    Write it out to the the a new XML file

There are many tutorials out there on how to use SAX, such as this one: How to parse XML using the SAX parser

If the "replacements" you need to do are very straightforward like "all <tag> objects under <parent-tag>" then maybe building the DOM and using XPath would work, but if your replacements are very arbitrary and unstructured then I'd go with parsers.

Community
  • 1
  • 1
MxLDevs
  • 19,048
  • 36
  • 123
  • 194