Java SE 平台上 XML 解析 API 的比较
我目前正在开发一个 RSS 提要阅读器,我想知道哪种 XML 解析 API 最适合它。 (请注意,我并不是在寻找 Feed 解析器库 - 它只是有关 XML API 研究的起点)
我正在寻找 Java 平台上各种 XML 解析 API 的概要,重点关注以下标准:
- 易于配置
- 配置是否在单独的文件中?
- 是否存在合理的默认值?
- 易于使用
- 节点导航 - 到兄弟姐妹、到子级、到父级。
- 访问/操作命名空间、属性、文本。
- 类层次结构是否经过深思熟虑或自然?
- 无效的 XML - 会发生什么情况(什么时候会失败?),以及在以下情况下我该怎么办:
- 遇到无效字符(编码或 XML 规范中禁止的字符)
- 树结构无效(例如,由于未转义的 HTML 标记)
以下是一些我认为有用但不重要的信息:
- 树 比较
- 可用实现的列表
我目前正在考虑 JVM 上的任何 XML API。
- 它可以是 Java 标准(DOM、SAX、StAX、JAXP),也可以是特定于实现的 API。
- 它可以是 JVM 上任何语言的 API(Scala、Groovy、Jython、JRuby...)——只需确保它与标准 Java API 相比添加了一些内容即可。
我相信构建这个线程的一个好方法是每个答案只有一个 API。
I am currently developing an RSS feed reader, and I am wondering which XML parsing API would be the best fit for that. (Please note that I am not looking for a Feed parser library - it is merely the starting point for that research about XML APIs)
I am looking for a rundown of the various XML parsing APIs on the Java platform, focusing on the following criteria:
- Ease of configuration
- Is the configuration in a separate file?
- Are there reasonable defaults?
- Ease of use
- Node navigation - to siblings, to children, to the parent.
- Access/Manipulation of Namespaces, Attributes, Text.
- Is the class hierarchy well-thought or natural?
- Invalid XML - what happens (when does it fail?), and what can I do when:
- an invalid character is encountered (forbidden in either the encoding or the XML spec)
- the tree structure is not valid (for example, because of unescaped HTML tags)
Here is some information that I would consider useful though not crucial:
- Performance comparisons
- A list of available implementations
I am currently considering any XML API on the JVM.
- It can be a Java standard (DOM, SAX, StAX, JAXP), or an implementation-specific API.
- It can be an API for any language on the JVM (Scala, Groovy, Jython, JRuby...) - just make sure that it adds something compared to the standard Java APIs.
I believe that a good way to structure this thread would be to only have one API per answer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
jaxp 不是一个实现,而是一个包装器/外观 api,您可以在其中插入多个解析器实现。所以你只剩下 sax、dom 和 stax。现在下面是两个很好的比较,您可以进行数学计算:
http:// /techstop.abidshafiq.com/2010/02/java-xml-api-comparison/
http://java.sun.com/performance/reference/whitepapers/ StAX-1_0.pdf
jaxp is not an implementation but a wrapper/facade api where u can plugin multiple parser implementations. so you are left with sax, dom and stax. now below are two good comparisions and you do the math:
http://techstop.abidshafiq.com/2010/02/java-xml-api-comparison/
http://java.sun.com/performance/reference/whitepapers/StAX-1_0.pdf
看这里,你会得到一把!
http://www.xml.com/pub/rg/Java_Parsers
但是,我见过我的一些朋友在他们的项目中使用这个。尽管 JAXP 被广泛使用,但这个看起来很有前途。
Apache Xerces 解析器版本 1.2.3 (http://xerces.apache.org/xerces-j/< /a>)
Look here, you'll get a handful!
http://www.xml.com/pub/rg/Java_Parsers
But, I had seen some of my friends using this one in their projects. Though JAXP is widely used, this one looks promising.
Apache Xerces parser version 1.2.3 (http://xerces.apache.org/xerces-j/)