I´m researching how to transform XML from one format to another in a Java project.
What alternatives are there and what are their pros and cons?
Alternatives I´ve found so far:
- XSLT/XQuery
- XML-binding both formats to Java and do the mapping in Java
- Groovy
If you’re transforming XML to XML, then you’ll only make extra work for yourself if you go via a non-XML representation (such as Java objects). Using a high-level declarative language is the way to go, and that means XSLT or XQuery.
In choosing between XSLT and XQuery, my usual advice is that XSLT is optimized for transformation and XQuery is optimized for query. By “transformation” I mean tasks in which most of the input appears in the output, just in a different form. By “query” I mean extracting nuggets of information from a sea of data.
Of course, all these technologies have a learning curve, and if you have a small one-off job to do, then that can be a valid factor in choosing your tools. But the best advice for a project doing XML and Java is to do as little Java as possible. Thinking about it as “a Java project” is probably a bad starting position.