views:

176

answers:

3

Hi,

normally I would use JaxB, XMLBeans or Simple to convert a XML file to a Java Object. In this case I can however only use Java5 and no external libraries (for several reasons).

What is the best way to do that? My XML input is very simple. What is the most flexible and elegant way to get the XML into a Java-Object (I don't really need real JavaBeans, since I just need GETTER).

Thanks!

+2  A: 

Well, you can do that using DOM implementation.

adatapost
+2  A: 

Java5 provides JaxP which includes DOM and SAX.

Which one to use depends largely on how big the XML document is and how fast you need to access elements. DOM will put the whole XML structure into memory, while SAX provides a serial streaming approach.

Binary Nerd
A: 

The most flexible way to do data binding is by using XPath see the article below http://onjava.com/pub/a/onjava/2007/09/07/schema-less-java-xml-data-binding-with-vtd-xml.html

vtd-xml-author
I have read the entire article and only noticed at the end, that it introduces an additional processing library not shipping with the Java5 JRE. Or do I miss anything?
The external lib would be excluded for many reasons. Manly extra size and license other then Apache or EPL.
if you are not using any external lib, then you can only use dom, sax and xml lib shipped with jdk 5... and that meant a lot of manual coding...
vtd-xml-author