java xml 开源框架,我在哪里可以找到的Java XML框架的详细比较?

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

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值