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:
I vote for XSLT
. It has the strong advantage that the transformation rules are separated from your java code. So later on, you can easily react to schema changes without touching your code.
And you can test/debug the transformation anywhere - no need to run the application.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With