用Java转换XML有哪些不同的方法? [英] What are the different approaches for transforming XML with Java?

查看:109
本文介绍了用Java转换XML有哪些不同的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究如何在一个Java项目中将XML从一种格式转换为另一种格式。

有什么替代方案,他们的优点和缺点是什么?






  1. XSLT / XQuery
  2. XML将这两种格式都绑定到Java,并执行Java中的映射

  3. Groovy


解决方案

到XML,那么如果你通过一个非XML表示(例如Java对象),你只会为自己做更多的工作。使用高级声明性语言是最好的选择,这意味着XSLT或XQuery。



在XSLT和XQuery之间进行选择时,我通常的建议是优化XSLT用于转换,XQuery针对查询进行了优化。 转型是指大多数投入出现在输出中的任务,只是形式不同而已。通过查询我的意思是从数据海中提取信息块。

当然,所有这些技术都有一个学习曲线,如果你有一个小的单向函数,关闭工作,那么这可能是选择工具的有效因素。但对于执行XML和Java的项目来说,最好的建议是尽可能少使用Java。把它看作一个Java项目可能是一个糟糕的开始。

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:

  1. XSLT/XQuery
  2. XML-binding both formats to Java and do the mapping in Java
  3. 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.

这篇关于用Java转换XML有哪些不同的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆