Ankur Raiyani
Ankur Raiyani

Reputation: 1709

What is the better way/technology to transform XML to XML in Java

I require to transform XML to XML using Java. I googled for that and i found few technologies as below

  1. JAXB
  2. Apache Cocoon
  3. XSLT

Can anyone suggest me the better way/technology from the above list? Please let me know if is there any other better option available.

Note: Want to avoid writing XSLTs.

Thank You.

Upvotes: 0

Views: 787

Answers (4)

I have found that saxon is an excellent xslt processor, capable of xslt 2.0. There is a huge difference between xslt 1.0 and 2.0. I believe it can also be extended in Java.

Upvotes: 0

Michael Kay
Michael Kay

Reputation: 163360

It's true that there is a learning curve associated with XSLT. It's also true that it's the best tool for the job. Bite the bullet and get learning.

Upvotes: 1

Alain BECKER
Alain BECKER

Reputation: 798

XSLT was created to transform XML to something, and is excellent at transforming to XML.

  • Depending on your requirements, pure XSLT could be enough ;
  • if your requirements go beyond native XSLT capabilities, using Apache Xalan, you can write your own extension functions in java.

Apache Cocoon is a great piece of software, with capabilities of chaining processing units. But it may be overkill. And in the end, you're likely to have to write XSLT for Cocoon to process.

I'm sorry I have no experience with JAXP (neither the SAX nor JDOM options), and can't provide you with pros or cons towards it… Except one good thing is that it provides a third option: XSLT ;-)

If you really don't want to use XSLT, maybe have a look into Groovy, which compiles to java classes, and is said to automagically transform XML to object graph, and object graphs to XML. Have a look at the following threads for a quick overview :

Last, maybe have a look at this quite similar question (and its answers):

Upvotes: 2

kostja
kostja

Reputation: 61558

If you want generic, complex transformations, then XSLT is the way to go - AFAIK it is the most powerful tool for the job.

For many simpler tasks, it may not be necessary. If you are just filling more or less uniform documents, like emails or reports, try using a template framework like freemarker.

I am not familiar with Cocoon and rather unsure how you would use JAXB for XML transformation.

Upvotes: 1

Related Questions