[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: "Michael Kay" <mike@s...>
  • To: "'Mukul Gandhi'" <gandhi.mukul@g...>,<xml-dev@l...>
  • Date: Wed, 9 Apr 2008 15:47:53 +0100

RE:  Best way to create an XML document
My preference is to use a SAX-like serializer driven by calls such as

startElement("x")
attribute("a", "3")
text("content")
endElement("x")

This avoids the overhead of creating a tree in memory, while still giving
the benefits of having the system take care of matters such as escaping
special characters.

There are a number of such interfaces around depending on your environment,
e.g. the XmlWriter in .NET. I tend to use the internal one in Saxon, of
course.

Michael Kay
http://www.saxonica.com/ 

> -----Original Message-----
> From: Mukul Gandhi [mailto:gandhi.mukul@g...] 
> Sent: 09 April 2008 15:00
> To: xml-dev@l...
> Subject:  Best way to create an XML document
> 
> Hi all,
>    Let's suppose I need to create an XML document from 
> scratch in a Java program.
> 
> What's the best way to do this?
> 
> I have seen that a quick way to do this is preparing a XML 
> string by hand.
> 
> For e.g.,
> 
> String xml_str = "<x><y><z/></y></x>";
> 
> I want to understand the pros and cons of this approach.
> 
> I most of the time prefer using an API like DOM to create an 
> in-memory representation, and then serializing the tree to String.
> 
> Following are my arguments in favor of using the DOM approach:
> 
> 1) Creating a XML string by hand can become cumbersome, if 
> XML is huge. Maintaining the correct parent child 
> relationship for a huge document can be difficult, if done by 
> hand (imagine a document of size 50 MB). This would lead to 
> difficult debugging. Using a DOM API can do this inherently in memory.
> 
> 2) It's difficult to remember correct XML name conventions if 
> done by hand.
> 
> for e.g., <9abc> is an invalid XML name (because it starts 
> with a number).
> 
> There are more rules for XML names.
> 
> Using DOM API does this automatically.
> 
> 3) Using DOM API can check well-formedness of entities (like, 
> &abc; etc). Doing this by hand in a string can become difficult.
> 
> I would appreciate thoughts about this subject from list members.
> 
> --
> Regards,
> Mukul Gandhi
> 
> ______________________________________________________________
> _________
> 
> XML-DEV is a publicly archived, unmoderated list hosted by 
> OASIS to support XML implementation and development. To 
> minimize spam in the archives, you must subscribe before posting.
> 
> [Un]Subscribe/change address: http://www.oasis-open.org/mlmanage/
> Or unsubscribe: xml-dev-unsubscribe@l...
> subscribe: xml-dev-subscribe@l... List archive: 
> http://lists.xml.org/archives/xml-dev/
> List Guidelines: http://www.oasis-open.org/maillists/guidelines.php
> 



[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.