OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Re: [xml-dev] Best way to create an XML document

On 16/04/2008, Mukul Gandhi <gandhi.mukul@gmail.com> wrote:
> I agree with you ...
>  On 4/15/08, Chris Burdess <dog@bluezoo.org> 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

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
Kernow: http://kernowforsaxon.sf.net/

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS