您可能需要检查这个有关最佳 XML 库的问题 及其顶部(XOM)答案; 有关 XOM 优点的大量详细信息。 (如果有不清楚的地方,请发表评论;Peter Štibraný 似乎对 XOM 了如指掌。)
如上所述,与标准 javax.xml 相比,XOM 在大多数任务中都非常快速且简单。 有关示例,请参阅 这篇文章关于用 Java 读取 XML 文件的最简单方法的问题。 我收集了一些很好的例子,这些例子使 XOM 看起来相当不错(而 javax.xml 则相当笨拙)。 :-)
所以我个人在评估之后开始喜欢 XOM(正如您在链接的帖子中看到的那样); 对于任何新的 Java 项目,我最有可能选择 XOM 进行 XML 处理。 我发现的唯一缺点是它不能直接< /em> 支持流式 XML(与我来自的 dom4j 不同),但有一个简单的解决方法它可以很好地传输。
You might want to check this question about the best XML library and its top (XOM) answer; lots of details about advantages of XOM. (Leave a comment if something is unclear; Peter Štibraný seems to know XOM inside and out.)
As mentioned, XOM is very quick and simple in most tasks compared to standard javax.xml. For examples, see this post in a question about the simplest way to read in an XML file in Java. I collected some nice examples that make XOM look pretty good (and javax.xml rather clumsy) there. :-)
So personally I've come to like XOM after evaluating (as you can see in the linked posts); for any new Java project I'd most likely choose XOM for XML handling. The only shortcoming I've found is that it doesn't directly support streaming XML (unlike dom4j where I'm coming from), but with a simple workaround it can stream just fine.
If it is one-pass, then you don't need to build the tree in memory. You can use SAX (fast, simple) or StAX (faster, not quite so simple).
If you need to keep the tree in memory to navigate, XOM or JDOM are good choices. DOM is the Choice Of Last Resort, whether it is level 1, 2, or 3, with or without extensions.
Xerces, which is the parser included with Java (although you should get the updated version from Apache and not use the one bundled with Java, even in 6.0), also has a streaming native interface called XNI.
If you want to hook other pre-made parts up in the chain, often SAX or StAX work well, since they might build their own model in memory. For example, the Saxon XSLT/XQuery engine works with DOM, SAX or StAX, but builds internally a TinyTree (default) or DOM (optional). DataDirect XQuery works with SAX, StAX or DOM also, but really likes StAX.
发布评论
评论(3)
您可能需要检查这个有关最佳 XML 库的问题 及其顶部(XOM)答案; 有关 XOM 优点的大量详细信息。 (如果有不清楚的地方,请发表评论;Peter Štibraný 似乎对 XOM 了如指掌。)
如上所述,与标准 javax.xml 相比,XOM 在大多数任务中都非常快速且简单。 有关示例,请参阅 这篇文章关于用 Java 读取 XML 文件的最简单方法的问题。 我收集了一些很好的例子,这些例子使 XOM 看起来相当不错(而 javax.xml 则相当笨拙)。 :-)
所以我个人在评估之后开始喜欢 XOM(正如您在链接的帖子中看到的那样); 对于任何新的 Java 项目,我最有可能选择 XOM 进行 XML 处理。 我发现的唯一缺点是它不能直接< /em> 支持流式 XML(与我来自的 dom4j 不同),但有一个简单的解决方法它可以很好地传输。
You might want to check this question about the best XML library and its top (XOM) answer; lots of details about advantages of XOM. (Leave a comment if something is unclear; Peter Štibraný seems to know XOM inside and out.)
As mentioned, XOM is very quick and simple in most tasks compared to standard javax.xml. For examples, see this post in a question about the simplest way to read in an XML file in Java. I collected some nice examples that make XOM look pretty good (and javax.xml rather clumsy) there. :-)
So personally I've come to like XOM after evaluating (as you can see in the linked posts); for any new Java project I'd most likely choose XOM for XML handling. The only shortcoming I've found is that it doesn't directly support streaming XML (unlike dom4j where I'm coming from), but with a simple workaround it can stream just fine.
您需要如何访问您的数据?
如果是一次性的,那么就不需要在内存中构建树。 您可以使用 SAX (快速、简单)或 StAX (更快,但不太简单)。
如果您需要将树保留在内存中进行导航,XOM 或 JDOM 是不错的选择。 DOM是最后的选择,无论是1级, 2 或 3,带或不带扩展。
Xerces 是 Java 附带的解析器(尽管您应该从 Apache 获取更新版本,而不是使用与 Java 捆绑的版本,即使在 6.0 中也是如此),它也有一个名为 XNI。
如果您想将其他预制部件挂接到链中,通常 SAX 或 StAX 效果很好,因为它们可能会在内存中构建自己的模型。 例如,Saxon XSLT/XQuery 引擎可与 DOM、SAX 或 StAX 配合使用,但在内部构建 TinyTree(默认)或 DOM(可选)。 DataDirect XQuery 也适用于 SAX、StAX 或 DOM,但真的喜欢 StAX。
How do you need to access your data?
If it is one-pass, then you don't need to build the tree in memory. You can use SAX (fast, simple) or StAX (faster, not quite so simple).
If you need to keep the tree in memory to navigate, XOM or JDOM are good choices. DOM is the Choice Of Last Resort, whether it is level 1, 2, or 3, with or without extensions.
Xerces, which is the parser included with Java (although you should get the updated version from Apache and not use the one bundled with Java, even in 6.0), also has a streaming native interface called XNI.
If you want to hook other pre-made parts up in the chain, often SAX or StAX work well, since they might build their own model in memory. For example, the Saxon XSLT/XQuery engine works with DOM, SAX or StAX, but builds internally a TinyTree (default) or DOM (optional). DataDirect XQuery works with SAX, StAX or DOM also, but really likes StAX.
与标准 W3C DOM 相比,XOM 速度极其。 如果这是您的首要任务,那么没有比这更好的了。
然而,它仍然是一个 DOM 类型的 API,因此内存效率不高。 它不是 SAX 或 STAX 的替代品。
XOM is extremely quick compared to the standard W3C DOM. If that's your priority, there's none better.
However, it's still a DOM-type API, and so it's not memory efficient. It's not a replacement for SAX or STAX.