Lists Home |
Date Index |
I want to add some elements to an existing XML document at well defined positions without modifing the concret representation of the XML document.
Especially I want to keep the overall 'formatting' of attributes and the indentation. Generally speaking, the so-called non-infoset
should remain unchanged.
My programming language is Java.
What is the best way?
- If I use DOM or SAX, the formatting of the attributes and others will be lost.
- Manually parsing the XML is a pain.
I'm thinking about a hybrid solution:
- parse the document with SAX,
- keep track of the location in the file with a Locator,
- generate new DOM nodes in the SAX ContentHandler at the defined position(s),
- stream out the original byte stream, mixed with the new nodes at the appropriate locations.
Seems to be less pain, but still looks rather complicated.
Do you have any better suggestions?
Is there something similar to SAX events that also regards the non-infoset?