Reputation: 62404
I'm learning Java EE 6 & Jax-RS (haven't started anything about Jax-RS yet) to build an xml api for my work. I have my java controllers setup and I'm looking now to use my models to generate XML output. I can't seem to find any XML libraries by searching Google. Can someone help point me in the right direction?
Upvotes: 2
Views: 381
Reputation: 17854
If you use JAX-RS, you can use @Produces("application/xml"), then you will have an xml api. JAX-RS works by default with JAXB.
See http://jersey.java.net/nonav/documentation/latest/jax-rs.html#d4e318
Upvotes: 5
Reputation: 39950
Java SE already includes XML parsers in three styles:
If you're going to use JAX-RS, you probably don't want to use these "low-level" XML libraries. JAX-RS should handle parsing requests and formatting responses for you. I believe it uses JAXB for this, also a part of the standard library. JAXB will serialise a Java object automatically based on annotations on the class and its fields / properties that control the serialisation.
Upvotes: 3
Reputation: 744
The libraries aren't JavaEE specific. For generating XML, StAX and JDOM are the most commonly used in my experience. StAX is part of the JDK. They also do XML parsing and validation.
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 X.Y). JDOM loads the entire document tree into memory, which eats up memory but performs faster.
Here's an overview comparing the two tools and JAXB.
Upvotes: 1
Reputation: 1091
Personally I like the simplicity of Simple XML http://simple.sourceforge.net/
Also you could consider using JAXB that comes with Java EE6. http://www.oracle.com/technetwork/articles/javase/index-140168.html
Upvotes: 1