This week's book giveaway is in the Design and Architecture forum.
We're giving away four copies of Communication Patterns: A Guide for Developers and Architects and have Jacqui Read on-line!
See this thread for details.
  • 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

Newbie Question

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I wanted to ask a very basic question. I have a java object and i want to serialize it as an xml file. How should i do it
a) Create a new document using DOM and then serialize it using XSLT
b) Create the xml file by simply writing data (along with the tags) to a file.
Pls. suggest.
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

a) Create a new document using DOM and then serialize it using XSLT
b) Create the xml file by simply writing data (along with the tags) to a file.


Following the simplest thing that could possibly work principle, I'd say b) is a better option. Especially when I don't quite see why you would need to use XSLT for serializing a DOM tree into disk as XML...?
 
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



use XSLT for serializing a DOM tree into disk as XML...?


With JAXP 1.1, this was the only way to serialize XML documents I guess.
Not sure if JAXP1.2 has added a standard way of serializing XML documents though.
On a side note I wonder if JAXP has been a huge success and if people have been doing XML processing on top of JAXP :roll:
I beleive there are always situations when we are better off using processor specific features. Can anybody share their views?
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

With JAXP 1.1, this was the only way to serialize XML documents I guess.


Ok. I think you guys are talking aboutRight?
I didn't consider that as being "XSLT" (which I associate to "having an .xsl file")...
 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, i meant identity transformation only.
 
Tomchi Tang
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply. Now i am convinced that DOM is a better option. On a little bit of research, I found there is another option available - JDom. What do you guys think about it - JDOM or DOM + XSLT.
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would probably stick to "DOM + XSLT" over JDom just to avoid adding yet-another third party library into the project but instead use a portable, standard piece of code.
 
Could you hold this puppy for a sec? I need to adjust this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic