• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Transforming java objects to xml (using xsl?)

 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is more a design question than anything else I guess. Here is the scenario:

SOAP template < header template < custom content xml template

I have several content xml files. There is only one header template and only one SOAP template. This part of the design I cannot change. I wish I could, but I can't.

The SOAP template and template wrapper will be appended with XSL.

So I have java objects that represent the data that needs to be transformed to the content xml. To make matters worse, the company could very well be changing the xml format in the future. So it seams to me that this is a good place to draw a line in the code to separate presentation and content. Am I doing ok or am I way off here?

The real question here is how do I get the data in an xml format? The first thing I thought of was DOM builder. But the XML format could change. It would sure be nice to use XSL for that so if they changed the xml format I would not have to change DOM code. But XSL is for transforming XML, not the java objects I have. So now I am stuck. Here are a couple of ideas I have had:

1. Just use DOM to generate my own proprietary XML that is then transformed with XSL into whatever the latest standard is at the time.

2. Have a blank XML file and transform it passing parameters to the XSL (this is nice because it skips the overhead of building the original proprietary xml, which will become trash the moment I have the result from the XSL...)

3. Do what everybody else here is doing and build the xml with a StringBuffer append().append.().append()... and duplicate the code whenever you need it... not!

Any thoughts?
 
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you looked at JaxB, it is relatively easy to convert a java object to XML which you could then easily transform to another xml format using xsl. Another similar technology would be Jibx, it pretty much does the same thing as JaxB but it's a little faster and possibly simpler.

Brian
 
Rusty Enisin
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Brian,

Thanks for the reply. I will look into those.
 
Ranch Hand
Posts: 691
Mac
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yup you can develop a common xml. You need to ask for the scop of it.
Then by using XSLT transform it into to common XML. Here you can use options like DOM, SAX or XML Beans.

And as told also look at JAXB.
reply
    Bookmark Topic Watch Topic
  • New Topic