适用于Java的最佳XML解析器 [英] Best XML parser for Java

查看:262
本文介绍了适用于Java的最佳XML解析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要阅读较小的(最多几个MB,UTF-8编码的)XML文件,浏览各种元素和属性,或许修改一些并将XML再次写回磁盘(最好是很好的,缩进格式化。)

I need to read smallish (few MB at the most, UTF-8 encoded) XML files, rummage around looking at various elements and attributes, perhaps modify a few and write the XML back out again to disk (preferably with nice, indented formatting).

对我的需求最好的XML解析器是什么?有很多可供选择。我知道的是:

What would be the best XML parser for my needs? There are lots to choose from. Some I'm aware of are:

  • JDOM
  • Woodstox
  • XOM
  • dom4j
  • VTD-XML
  • Xerces-J
  • Crimson

当然是JDK中的那个(我使用的是Java 6)。我对Xerces很熟悉,但发现它很笨重。

And of course the one in the JDK (I'm using Java 6). I'm familiar with Xerces but find it clunky.

建议?

推荐答案

如果速度和内存没问题, dom4j 是一个非常好的选择。如果你需要速度,使用像 Woodstox 这样的StAX解析器是正确的方法,但你必须编写更多的代码来完成工作,你必须习惯于在流中处理XML。

If speed and memory is no problem, dom4j is a really good option. If you need speed, using a StAX parser like Woodstox is the right way, but you have to write more code to get things done and you have to get used to process XML in streams.

这篇关于适用于Java的最佳XML解析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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