在哪里可以找到 Java XML 框架的详细比较? [英] Where I can find a detailed comparison of Java XML frameworks?

查看:23
本文介绍了在哪里可以找到 Java XML 框架的详细比较?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的 Java 项目选择一个 XML 处理框架,但我迷失了名称..XOM、JDOM 等.我在哪里可以找到所有流行的 Java XML 框架的详细比较?

解决方案

正如 Blaise 指出的那样,坚持标准.但是在此期间创建了多个标准来解决不同的问题/用例.选择哪一个完全取决于您的要求.希望下面的对比能帮助你选对.

现在您必须选择两件事.APIAPI 的实现(有很多)

API

SAX:优点

  • 基于事件
  • 内存高效
  • 比 DOM 快
  • 支持模式验证

SAX:缺点

  • 没有对象模型,你必须利用事件并创造你自己
  • xml 的单一解析,并且只能前进
  • 只读 api
  • 不支持 xpath
  • 有点难使用

DOM:优点

  • 内存对象模型
  • 保持元素顺序
  • 双向
  • 读写api
  • xml 操作
  • 使用简单
  • 支持模式验证

DOM:缺点

  • 内存占用较大的 XML 文档(通常用于 XML 文档小于 10 mb)
  • 通用模型,即您使用节点

Stax:优点

  • 最好的 SAX 和 DOM,即易于使用 DOM和 SAX 的效率
  • 内存高效
  • 拉模型
  • 读写api
  • 支持子解析
  • 可以同时阅读多个文档在一个线程中
  • 并行处理 XML 更容易

Stax:缺点

  • 不支持模式验证(到目前为止我记得,不确定他们是否有现在添加)
  • 只能像萨克斯一样前进
  • 没有 xml 操作

JAXB:优点

  • 允许您访问和处理 XML无需了解 XML 的数据
  • 双向
  • 内存效率比 DOM 高
  • SAX 和 DOM 是通用解析器,其中因为 JAXB 创建了一个特定于您的 XML 架构
  • 数据转换:JAXB可以转换xml到 java 类型
  • 通过对象支持 XML MANIPULATION应用程序接口

JAXB:缺点

  • 只能解析有效的 XML

Trax:用于使用 XSLT 将 XML 从一种形式转换为另一种形式

实施

SAX、DOM、Stax、JAXB 只是规范.有许多这些规范的开源和商业实现.大多数情况下,您可以坚持使用 JDK 或您的应用程序服务器附带的内容.但有时您需要使用默认提供的不同实现.这是您可以欣赏 JAXP 包装器 api 的地方.JAXP 允许您通过配置切换实现,而无需修改您的代码.它还提供了一个独立于解析器/规范的 API,用于解析、转换、验证和查询 XML 文档.

各种实现的性能和其他比较

<小时>

现在标准很好,但有时您会遇到这种疯狂的用例,您必须支持解析 100 GB 大小的 XML 文档,或者您需要超快 XML 的处理(可能是您正在实施 XML 解析器芯片),这时您需要转储标准并寻找不同的做事方式.它是关于为正确的工作使用正确的工具!这就是我建议您查看 vtd-xml 的地方

在 SAX 和 DOM 的最初几天,人们想要比它们提供的 API 更简单的 API.JDOMdom4jXmlBeansJiBXCastor 是我所知道的流行音乐.>

I'm trying to choose an XML-processing framework for my Java projects, and I'm lost in names.. XOM, JDOM, etc. Where I can find a detailed comparison of all popular Java XML frameworks?

解决方案

As Blaise pointed out stick with the standards. But there are multiple standards created over the period to solve different problems/usecases. Which one to choose completely depends upon your requirement. I hope the below comparison can help you choose the right one.

Now there are two things you have to choose. API and the implementations of the API (there are many)

API

SAX: Pros

  • event based
  • memory efficient
  • faster than DOM
  • supports schema validation

SAX: Cons

  • No object model, you have to tap into the events and create your self
  • Single parse of the xml and can only go forward
  • read only api
  • no xpath support
  • little bit harder to use

DOM: Pros

  • in-memory object model
  • preserves element order
  • bi-directional
  • read and write api
  • xml MANIPULATION
  • simple to use
  • supports schema validation

DOM: Cons

  • memory hog for larger XML documents (typically used for XML documents less than 10 mb)
  • slower
  • generic model i.e. you work with Nodes

Stax: Pros

  • Best of SAX and DOM i.e. Ease of DOM and efficiency of SAX
  • memory efficient
  • Pull model
  • read and write api
  • supports subparsing
  • can read multiple documents same time in one single thread
  • parallel processing of XML is easier

Stax: Cons

  • no schema validation support (as far as I remember, not sure if they have added it now)
  • can only go forward like sax
  • no xml MANIPULATION

JAXB: Pros

  • allows you to access and process XML data without having to know XML
  • bi-directional
  • more memory efficient than DOM
  • SAX and DOM are generic parsers where as JAXB creates a parser specific to your XML Schmea
  • data conversion: JAXB can convert xml to java types
  • supports XML MANIPULATION via object API

JAXB: Cons

  • can only parse valid XML

Trax: For transforming XML from 1 form to another form using XSLT

Implementations

SAX, DOM, Stax, JAXB are just specifications. There are many open source and commercial implementations of these specifications. Most of the time you can just stick with what comes with JDK or your application server. But sometimes you need to use a different implementation that provided by default. And this is where you can appreciate the JAXP wrapper api. JAXP allows you to switch implementations through configuration without the need to modify your code. It also provides a parser/spec independent api for parsing, transformation, validation and querying XML documents.

Performance and other comparisons of various implementations


Now standards are good but once in a while you encounter this crazy usecase where you have to support parsing of XML document that is 100 gigabytes of size or you need ultra fast processing of XML (may be your are implementing a XML parser chip) and this is when you need to dump the standards and look for a different way of doing things. Its about using the right tool for the right job! And this is where I suggest you to have a look at vtd-xml

During the initial days of SAX and DOM, people wanted simpler API's than provided by either of them. JDOM, dom4j, XmlBeans, JiBX, Castor are the ones I know that became popular.

这篇关于在哪里可以找到 Java XML 框架的详细比较?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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