Search code examples
javaxmlxml-parsingstax

Inserting XMLEvent using Location object


Is there a way to write XMLEvent using XMLEventWriter at the location of another XMLEvent read using XMLEventReader?

Thanks,


Solution

  • As far as I know, you cannot edit an XML file in-place using XMLReader. You can copy the entire XML to an output file (or stream) by sending all events from an XMLReader directly to an XMLWriter. You can then create your own XMLEvents on the fly and feed them to the XMLWriter at the appropriate time and they will show up in the new document.