java - 您推荐什么 Java XML 库(替换 dom4j)?

标签 java xml dom4j

我正在寻找类似 dom4j 的东西,但没有 dom4j 的缺点,例如文档错误或缺失以及似乎停滞不前的开发状态。

背景:我一直在使用and advocating dom4j,但对此感觉并不完全正确,因为我知道该库远非最佳(例如:查看 XSLT 相关 Stylesheet 类中的方法是如何记录的;您会将什么作为 String 传递给 run()模式参数?)

要求: 该库应该使基本的 XML 处理比 using 时更容易。 pure JDK (javax.xmlorg.w3c.dom 包)。像这样的事情:

  • 将 XML 文档(从文件或字符串)读取到对象中,轻松遍历和操作 DOM,执行 XPath 查询并针对它运行 XSLT。
  • 在您的 Java 代码中构建 XML 文档,添加元素和属性以及数据,最后将文档写入文件或字符串。

我真的很喜欢 dom4j promises ,实际上:“易于使用的开源库,用于处理 XML、XPath 和 XSLT [...],完全支持 DOM、SAX 和 JAXP。”即将推出的 dom4j 2.0 确实声称可以修复一切:充分利用 Java 5 并添加缺失的文档。但不幸的是,如果你 look closer :

Warning: dom4j 2.0 is in pre-alpha stage. It is likely it can't be compiled. In case it can be compiled at random it is likely it can't run. In case it runs occasionally it can explode suddenly. If you want to use dom4j, you want version 1.6.1. Really.

...网站已经说过很长时间了。那么 dom4j 有什么好的替代品吗?请为您的首选库提供一些理由,而不仅仅是转储名称和链接。 :-)

最佳答案

当然,XOM :-)

XOM is designed to be easy to learn and easy to use. It works very straight-forwardly, and has a very shallow learning curve. Assuming you're already familiar with XML, you should be able to get up and running with XOM very quickly.

我使用 XOM 已经好几年了,我仍然非常喜欢它。易于使用,网络上有大量文档和文章,API 在版本之间不会改变。最近发布了 1.2。

XOM is the only XML API that makes no compromises on correctness. XOM only accepts namespace well-formed XML documents, and only allows you to create namespace well-formed XML documents. (In fact, it's a little stricter than that: it actually guarantees that all documents are round-trippable and have well-defined XML infosets.) XOM manages your XML so you don't have to. With XOM, you can focus on the unique value of your application, and trust XOM to get the XML right.

查看网页 http://www.xom.nu/用于常见问题解答、Cookbook、设计原理等。如果所有东西的设计都充满爱心:-)

作者还写过 What's Wrong with XML APIs (and how to fix them) . (基本上,XOM首先存在的原因)

这里也是关于 XOM 的作者对 Artima 的 5 部分采访,他们谈论 what's wrong with XML APIs , The Good, the Bad, and the DOM , A Design Review of JDOM , Lessons Learned from JDOM最后是 Design Principles and XOM .

关于java - 您推荐什么 Java XML 库(替换 dom4j)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/831865/

相关文章:

java - JNLP找不到使用Maven构建的主类

c# - C#反序列化在InvalidOperationException上捕获并继续。怎么样?

android - 升级到 Android Studio 3.0 Canary 5 导致 "IllegalArgumentException: AppCompat does not support the current theme features.."

java - 如何将dom4j文档对象转换为字符串

java - NoClassDefFound错误: org/dom4j/io/SAXReader

java - 用 dom4j 或 jdom 或任何方式解析 xml

java - 尝试使用来自 Java (JNA) 的 DLL。无法加载库异常

Java:Java 6 何时准备好用于最终用户桌面应用程序?

java - 什么是基于 C 的服务和基于 Java 的服务?

c# - 更改 Crystal Report 的 XML 数据源