JAXB defines an API for reading and writing Java objects to and from XML documents.
http://www.vogella.com/articles/JAXB/article.html
Using schemagen, the JAXB schema generator tool, you can start with a set of Java classes and generate an XML schema.
Using JAXB xjc tooling to generate JAXB classes from an XML schema file
- Define an xsd file.
- Run xjc against the xsd file
- Java class will be generated
Using the JAXB runtime to marshal and unmarshal XML documents
- Marshal JAXB objects to XML instance documents.
JAXBContext jc = JAXBContext.newInstance("myPackageName");
//Create marshaller
Marshaller m = jc.createMarshaller();
//Marshal object into file.
m.marshal(myJAXBObject, myOutputStream);
- Unmarshal XML files to JAXB objects.
JAXBContext jc = JAXBContext.newInstance("myPackageName");
//Create unmarshaller
Unmarshaller um = jc.createUnmarshaller();
//Unmarshal XML contents of the file myDoc.xml into your Java
object instance.
MyJAXBObject myJAXBObject = (MyJAXBObject)
um.unmarshal(new java.io.FileInputStream( "myDoc.xml" ));
No comments:
Post a Comment