I have managed to parse xml files using SAX and DOM and have currently created an xml file using DOM as well.
I have now been tasked with using another API to generate an xml file other than DOM.
I was wondering if it is posibble to use SAX to generate the XML file or if there is any other way? Obviously not by just printing lines to a file
tom davies wrote:Currently using stax now actually. Seems very simple, i just don't seem to have the indentation like i do with DOM.
DOM doesn't automatically produce pretty-printed documents either, if you're seeing that then either the indentation was already in the input document or you're running it through some other process which does indentation.
Indentation is just done by inserting white-space text nodes of the right sort in the right place. You'll need new-lines after end tags (and other places too, look at pretty-printed documents to see how its done) and you'll need a varying number of space characters before start tags depending on the depth of nesting. You could do this in StAX if you liked, I've done it when providing SAX events to a serializer, the complexity of what you would have to do is proportional to the complexity of your XML and the logic required to produce it.
From the data point of view, indentation is unnecessary. So if you're just producing the XML to be processed by some other computer system, then don't bother with it. You only need it to make the XML be more human-readable.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com