Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EclipseLink/UserGuide/MOXy/Runtime/Bootstrapping/Generating Schema"

m (linked to example)
Line 39: Line 39:
 
</source></li>
 
</source></li>
 
</ol>
 
</ol>
 
 
{{EclipseLink_MOXy
 
|next=    [[EclipseLink/UserGuide/MOXy/Runtime/Bootstrapping_Dynamic|Dynamic Bootstrapping]]
 
|previous= [[EclipseLink/UserGuide/MOXy/Runtime/Bootstrapping/Multiple_Projects|From Multiple Projects]]
 
|up=      [[EclipseLink/UserGuide/MOXy/Runtime/Bootstrapping|Bootstrapping]]
 
|version=2.2.0 DRAFT}}
 

Revision as of 12:44, 15 June 2011

EclipseLink MOXy

Eclipselink-logo.gif
EclipseLink
Website
Download
Community
Mailing ListForumsIRCmattermost
Issues
OpenHelp WantedBug Day
Contribute
Browse Source

Elug example icon.png Examples

Generating an XML Schema

To generate an XML schema from a Java object model:

  1. Create a class that extends javax.xml.bind.SchemaOutputResolver.
    private class MySchemaOutputResolver extends SchemaOutputResolver {
     
        public Result createOutput(String namespaceURI, String suggestedFileName) throws IOException {
            File file = new File(suggestedFileName);
            StreamResult result = new StreamResult(file);
            result.setSystemId(file.toURI().toURL().toString());
            return result;
        }
     
    }
  2. 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);

Copyright © Eclipse Foundation, Inc. All Rights Reserved.