[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Best way to create an XML document
For me, creating an XML document from scratch within a program should mean that it can't be a huge document... But, still, I do appreciate not having too much program lines so I really prefer the string approach. You can always copy/paste the string in a text editor (I use NotePad++ myself...) which will check it is well-formed ! I really would like a programming language version of Java, C#, PHP,... where XML would be an effective internal type such as string or integer so the compiler could check it and optimize its loading because, with the string approach or the DOM approach, controls are always done at runtime and it's useless... Alain COUTHURES <agenceXML> http://www.agencexml.com Mukul Gandhi a écrit : > 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. > >
[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
|