|
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 |
|
(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. 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. |