[英]Where can I find Java EE 6 XML Libraries
I'm learning Java EE 6 & Jax-RS (haven't started anything about Jax-RS yet) to build an xml api for my work. 我正在学习Java EE 6和Jax-RS(还没有开始关于Jax-RS的任何事情)来为我的工作构建一个xml api。 I have my java controllers setup and I'm looking now to use my models to generate XML output.
我有我的java控制器设置,现在我正在寻找使用我的模型来生成XML输出。 I can't seem to find any XML libraries by searching Google.
我似乎无法通过搜索Google找到任何XML库。 Can someone help point me in the right direction?
有人能指点我正确的方向吗?
If you use JAX-RS, you can use @Produces("application/xml"), then you will have an xml api. 如果您使用JAX-RS,您可以使用@Produces(“application / xml”),然后您将拥有一个xml api。 JAX-RS works by default with JAXB.
JAX-RS默认使用JAXB。
See http://jersey.java.net/nonav/documentation/latest/jax-rs.html#d4e318 见http://jersey.java.net/nonav/documentation/latest/jax-rs.html#d4e318
Java SE already includes XML parsers in three styles: Java SE已经包含三种样式的XML解析器:
If you're going to use JAX-RS, you probably don't want to use these "low-level" XML libraries. 如果您打算使用JAX-RS,您可能不希望使用这些“低级”XML库。 JAX-RS should handle parsing requests and formatting responses for you.
JAX-RS应该为您处理解析请求和格式化响应。 I believe it uses JAXB for this, also a part of the standard library.
我相信它使用JAXB ,也是标准库的一部分。 JAXB will serialise a Java object automatically based on annotations on the class and its fields / properties that control the serialisation.
JAXB将根据类及其控制序列化的字段/属性的注释自动序列化Java对象。
The libraries aren't JavaEE specific. 这些库不是JavaEE特有的。 For generating XML, StAX and JDOM are the most commonly used in my experience.
为了生成XML,StAX和JDOM是我的经验中最常用的。 StAX is part of the JDK.
StAX是JDK的一部分。 They also do XML parsing and validation.
他们还进行XML解析和验证。
A couple of tutorials: 1 2 几个教程: 1 2
StAX uses an event based model (read the document and when you see element X do something) and unsuprisingly JDOM uses syntax similar to DOM (find element XY). StAX使用基于事件的模型(读取文档,当您看到元素X执行某些操作时),并且毫无疑问,JDOM使用类似于DOM的语法(查找元素XY)。 JDOM loads the entire document tree into memory, which eats up memory but performs faster.
JDOM将整个文档树加载到内存中,这会占用内存但执行速度更快。
Here's an overview comparing the two tools and JAXB. 这是一个比较两个工具和JAXB的概述。
Personally I like the simplicity of Simple XML http://simple.sourceforge.net/ 就个人而言,我喜欢Simple XML的简单性http://simple.sourceforge.net/
Also you could consider using JAXB that comes with Java EE6. 您还可以考虑使用Java EE6附带的JAXB。 http://www.oracle.com/technetwork/articles/javase/index-140168.html
http://www.oracle.com/technetwork/articles/javase/index-140168.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.