This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
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
if i am not wrong, if you are a beginner in xml, stax is the answer for you in this case. look into it first. jaxb, xslt, etc. are solutions to more complicated situations.
tom davies
Ranch Hand
Joined: Apr 27, 2012
Posts: 168
posted
0
Kathleen Angeles wrote:if i am not wrong, if you are a beginner in xml, stax is the answer for you in this case. look into it first. jaxb, xslt, etc. are solutions to more complicated situations.
Currently using stax now actually. Seems very simple, i just don't seem to have the indentation like i do with DOM.
Vinod Tiwari
Ranch Hand
Joined: Feb 06, 2008
Posts: 458
posted
0
Try XMLBean its very easy. You may also try XSLT. I have not tried other solutions and hence can't comment on them.
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 agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.