If you have XML files filed with data and want to map it to java object inside your application you can achieve it easy using IBM Rational Application Developer 8 (RAD).
To do this, necessary things are:
- Data in the form of XML file
- XML to XML schema generator
- IBM RAD tool
JAXB stands for Java Architecture for XML Binding. JAXB provides ability to marshal Java objects into XML and the inverse, i.e. to unmarshal XML back into Java objects. To create appropriate class for XML file JAXB requests XML schema (XSD) for XML data. An XML Schema describes the structure of an XML document.
Very often, in real life, XML files are created and populated with data but without XSD schema. Using XML file to XML schema generator this problem can be solved. There are a lot of on-line generators and one of them is: http://www.freeformatter.com/xsd-generator.html
Copy-paste your XML into generator and click Generate XSD. Copy generated code (XSL schema ) and paste it into new created file inside RAD. Save file with xsd extension. Then right click and choose New. Type jaxb and select Schema to JAXB Java Classes option.
Click Next.
Choose your .xsd file and click Next.
Click Generate serializable JAXB classes and finish.
RAD will generate java and class files inside generated folder in target container.
The class name is the same as the XML root element name.
No comments:
Post a Comment