JAXB 与 DOM 和 SAX [英] JAXB vs DOM and SAX

查看:29
本文介绍了JAXB 与 DOM 和 SAX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一段时间以来,我一直在使用 DOM 来解析我的小型 xml 文档.阅读有关 JAXB 的内容后(http://www.oracle.com/technetwork/articles/javase/index-140168.html),我打算使用 JAXB 代替 DOM.

I have been using DOM for parsing my small xml docs for sometime.Afer reading about the JAXB (http://www.oracle.com/technetwork/articles/javase/index-140168.html), I'm planning to use JAXB instaed of DOM.

请告诉我这是否是正确的方法.

Please let me know if this will be a right approach.

推荐答案

JAXB 不能直接与 DOM 和 SAX 相提并论.Java DOM 和 SAX 解析 API 是用于解析 XML 文档的较低级别的 API,而 JAXB(用于 XML 绑定的 Java API)是用于将 XML 元素和属性转换为 Java 对象层次结构(反之亦然)的较高级别的 API.JAXB 的实现很可能会在幕后使用 DOM 或 SAX 解析器来对 XML 输入数据进行实际解析.

JAXB is not directly comparable to DOM and SAX. The Java DOM and SAX parsing APIs are lower-level APIs to parse XML documents, while JAXB (Java API for XML Binding) is a higher-level API for converting XML elements and attributes to a Java object hierarchy (and vice versa). Implementations of JAXB will most likely use a DOM or SAX parser behind the scenes to do the actual parsing of the XML input data.

通常您希望将 XML 文档的内容转换为 Java 程序中的对象.如果这是您想要做的事情,那么 JAXB 可能更易于使用,并且与使用 DOM 或 SAX 解析 API 时相比,您需要编写的代码更少.

Often you'll want to convert the content of an XML document into objects in your Java program. If this is what you want to do, then JAXB will probably be easier to use and you'll need to write less code than when you would be using the DOM or SAX parsing API.

这是否适合您的案例取决于您的项目的功能和技术要求.

Whether it's the right approach for your case depends on exactly what the functional and technical requirements are for your project.

这篇关于JAXB 与 DOM 和 SAX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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