Difference between revisions of "EclipseLink/UserGuide/MOXy/Runtime/Bootstrapping/Generating Schema"
< EclipseLink | UserGuide | MOXy | Runtime | Bootstrapping
m (re-added footer) |
m |
||
Line 1: | Line 1: | ||
+ | '''[[Image:Elug_draft_icon.png|Warning]] For the current release, see [http://www.eclipse.org/eclipselink/documentation/2.4/moxy Developing JAXB Applications Using EclipseLink MOXy, EclipseLink 2.4] | ||
+ | ''' | ||
+ | ---- | ||
+ | |||
{{EclipseLink_UserGuide | {{EclipseLink_UserGuide | ||
|info=y | |info=y |
Revision as of 09:50, 23 July 2012
For the current release, see Developing JAXB Applications Using EclipseLink MOXy, EclipseLink 2.4
EclipseLink MOXy
EclipseLink | |
Website | |
Download | |
Community | |
Mailing List • Forums • IRC • mattermost | |
Issues | |
Open • Help Wanted • Bug Day | |
Contribute | |
Browse Source |
Key API
Examples
Generating an XML Schema
To generate an XML schema from a Java object model:
- Create a class that extends javax.xml.bind.SchemaOutputResolver.
private class MySchemaOutputResolver extends SchemaOutputResolver { public Result createOutput(String uri, String suggestedFileName) throws IOException { File file = new File(suggestedFileName); StreamResult result = new StreamResult(file); result.setSystemId(file.toURI().toURL().toString()); return result; } }
- Use an instance of this class with JAXBContext to capture the generated XML Schema.
Class[] classes = new Class[4]; classes[0] = org.example.customer_example.AddressType.class; classes[1] = org.example.customer_example.ContactInfo.class; classes[2] = org.example.customer_example.CustomerType.class; classes[3] = org.example.customer_example.PhoneNumber.class; JAXBContext jaxbContext = JAXBContext.newInstance(classes); SchemaOutputResolver sor = new MySchemaOutputResolver(); jaxbContext.generateSchema(sor);