[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Best way to create an XML document

  • From: "Andrew Welch" <andrew.j.welch@g...>
  • To: "Mukul Gandhi" <gandhi.mukul@g...>
  • Date: Wed, 16 Apr 2008 09:23:56 +0100

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!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.