[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Best way to create an XML document
On 16/04/2008, Mukul Gandhi <gandhi.mukul@g...> wrote: > I agree with you ... > > On 4/15/08, Chris Burdess <dog@b...> wrote: > > Others on this list have suggested using an XSLT transform or JAXB, > > which are pretty heavyweight solutions for achieving a simple thing. > > > > Since version 1.6, Java has supported the javax.xml.stream package, > > so the most straightforward way would be to use an XMLStreamWriter > > assuming you're happy with using this version of Java. > > > > http://java.sun.com/javase/6/docs/api/javax/xml/stream/XMLStreamWriter.html It's available to previous versions of Java through JSR 173, see: https://sjsxp.dev.java.net/ It's really, really useful for parsing XML when you need to know in advance what the XML contains before you get there. Using SAX you need to manange that yourself, with this you can "peek" ahead and do the prep work before the events come in for real. For creating XML I'm not aware of any major advantages over any other technique, but I haven't used it that much. Obviously the big plus for Java 6 is that it's part of the jdk. The JAXB suggestion is for anyone tired of hand crafting the parsing/serializing of XML. Given large but trivial XML, it can take a while to write the enum for the names, write the parser, write the serializer, write the tests, write the controlling code... and write the container classes. With this you can just annotate those container classes and you're pretty much done. If a new element comes along, just update the container class and it's ready. With a custom parsing solution, you'd need to modify four places: the container class, the names enum, and the parsing and serializing classes. Anyone new to SAX parsing should definitely go the manual route first, experience the joy of parsing mixed content etc. but I'm sure this is the future. -- Andrew Welch http://andrewjwelch.com Kernow: http://kernowforsaxon.sf.net/
[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] |
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|