Skip to content
Advertisement

XML to Java Object

I am trying to convert an XML file to a Java Object, now, I have read of JAXB, XStream, Sax and DOM, I’d like to convert this sort of type of xml:

JavaScript

it might be as well as:

JavaScript

I wanted to know if there is anything out there (and possibly not 3rd party) that I can use, without declaring a template in DTD or in JAXB in XSD but Java (therefore I will declare a java class called testxml with all the relevant variable i.e. testtype, duration, status>

Thank you all for your time.

Advertisement

Answer

The class below using JAXB Annotations will do exactly what you need, no need to create an XSD or a template using Java 1.6+:

JavaScript

Using this as test.xml:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement