Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

How To Creating XML Docs With Java?

 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a real basic question, but eveything I have read and seen so far is about parsing XML docs and storing them, not about creating them.
My question is, what is the proper way to create an XML doc from a database using Java API's.
What API's are necessary and should the database schema be set up in any special way to facilitate the creating of the XML docs.
Thanks in advance for the help here.
 
Rob Levo
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, can someone provide a simple example of creating an XML doc from a database.
Thanks again.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Basically you have two choices.
1. Create an in memory Document, create and add Element objects to it, transform to an output stream.
Advantages: rigourous
Disadvantages: a real pain to program
2. Just write all the various tags, etc with typical Java text writing methods.
Advantages: fast to program, runs fast
Disadvantages: may not write good XML
Personally I always go for 2 - you can have constant strings in your program for many of the tags and write great hunks of XML is a single statement.
Bill
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bill. How are you doing?

and write great hunks of XML is a single statement.


Can you give an example of a single statement that will write great hunks of XML?
Oh, and when are you going to write an exam cram book for the SCJWD exam. I need one.
Thanks
Mark
[ January 21, 2002: Message edited by: Mark Spritzler ]
 
Rob Levo
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by William Brogden:
Basically you have two choices.
1. Create an in memory Document, create and add Element objects to it, transform to an output stream.
Advantages: rigourous
Disadvantages: a real pain to program
2. Just write all the various tags, etc with typical Java text writing methods.
Advantages: fast to program, runs fast
Disadvantages: may not write good XML
Personally I always go for 2 - you can have constant strings in your program for many of the tags and write great hunks of XML is a single statement.
Bill


Thanks Bill, always good to hear from you.
Can you provide or point me in the direction of an example of creating an XML doc from a database.
I am especially interested in the mechanism you use to write a lot of XML at one time. Is it just a matter of storing a String in memory and then writing out the entire String to a file a one time?
Performace will be a key issue in the app I am writing so I do not want a lot of I/O overhaead.
Thanks again Bill,
Rob
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Writing XML from static strings is easy - here is an example from the SOAP book where two static String arrays provide the bulk of the document which is built in a StringBuffer:

Instead of String[] I could have used single long strings but this is a little clearer. For the ultimate in speed, these could be stored as byte[] to avoid character conversions.
Bill
 
Rob Levo
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bill, one more question regarding the creation of XML files.
Would it be more efficient to use one of the binding packages that maps classes to and from XML?
Thanks again, and good luck with the new SOAP book.
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Would it be more efficient to use one of the binding packages that maps classes to and from XML?"
Certainly not! They create lots of objects with short life spans. If you are going for speed at the expense of programming difficulty you must:
1.minimize creating objects that will be discarded
2. minimize character conversions with String writers and readers

Bill
 
reply
    Bookmark Topic Watch Topic
  • New Topic