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?
asked Sep 09 '11 at 10:15
(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.
answered Sep 09 '11 at 12:04
Alistair A. Israel
JAXB or JAXP
answered Feb 06 at 00:19