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

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

问题描述

我需要读取较小的(最多几 MB,UTF-8 编码)XML 文件,翻找各种元素和属性,也许修改一些并将 XML 重新写回磁盘(最好使用 nice,缩进格式).

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:

当然还有 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天全站免登陆