I am currently trying to read in an XML file, make minor changes (change the value of some attributes) and write it again.
I wanted to use the StAX ( javax.xml.stream.XMLStreamReader) analyzer to read in each case, see if it was the one I wanted to change, and then pass it directly to the StAX ( javax.xml.stream.XMLStreamReader) record if any changes are required.
Unfortunately, this does not look so simple: the writer has no way to take the type of event and the parser object, only methods like this writeAttributeand writeStartElement. Obviously, I could write a large switch statement with an argument for every possible element type that might appear in an XML document, and just write it back, but it seems like a ton of problems for something similar, which should be simple.
Is there something I am missing that makes it easy to write a very similar XML document to the one you read using StAX?
source
share