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

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

问题描述

我一直在使用DOM来解析我的小xml文档。阅读有关JAXB的信息( http://www.oracle.com/technetwork/articles/javase/index-140168.html ),我打算使用JAXB instaed of 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天全站免登陆