login about faq

i am using spring portlet for liferay. i have already searched the internet for a more suitable way but i dont like the implementation, in which i have to use document builder and parse the object's field one by one and set it to a DocumentBuilder's element.

is there a cleaner or smarter way to do this?

thanks

asked Sep 09 '11 at 10:15

maryon's gravatar image

maryon
15010


(You probably mean it the other way around: to parse or 'unmarshal' an XML document into a POJO/object.)

Without resorting to "low-level" DOM or SAX, you have several options:

JAXB is the 'reference' framework for JavaEE. However, it's not the simplest or most un-intrusive since it requires you to use annotations and write XML schema.

There's JiBX which aims to be much simpler.

Apache Commons Digester is similar in philosophy to JiBX, aiming to keep things simple, but if I'm reading it correctly can only work one-way (from XML to POJO).

Then there's also XMLBeans.

Each library has different approaches, strengths and weaknesses. Suggest you play around with one or two and just go with whatever works for you at the moment.

link

answered Sep 09 '11 at 12:04

Alistair%20A.%20Israel's gravatar image

Alistair A. Israel
3.1k210

thanks... ill take a look at those.

anyway i actually need to parse POJO/Object to XML and vice versa. because im connecting to an api that can only provide XML sent over POST.

(Sep 09 '11 at 14:07) maryon maryon's gravatar image

JAXB or JAXP

link

answered Feb 06 at 00:19

sarmiento_eric's gravatar image

sarmiento_eric
11

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×63
×7
×2
×2

Asked: Sep 09 '11 at 10:15

Seen: 631 times

Last updated: Feb 06 at 00:19