Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create XSD from Java bean or from XML using JAXB

Tags:

java

xml

jaxb

xsd

I am using this code

JAXBContext jc = JAXBContext.newInstance(Bookdata.class);
Bookdata bookdata=new Bookdata();
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(bookdata, (OutputStream) output);

But it is generating XML But i need XSD I Need to create XSD like this:

<ArrayOfCommandInfoDTO>
     <CommandInfoDTO>
        <a:allowAddingGameCenterFriends>true</a:allowAddingGameCenterFriends>
        <a:enter code here>allowAppInstallation>true</a:allowAppInstallation>
        <a:allowAssistant>true</a:allowAssistant>
        <a:allowAssistantWhileLocked>true</a:allowAssistantWhileLocked>
        <a:allowCamera>true</a:allowCamera>
     </CommandInfoDTO>
</ArrayOfCommandInfoDTO>

So Please tell me how to create XSD from java Beans or from XML

like image 476
pankaj369 Avatar asked Jun 14 '26 16:06

pankaj369


1 Answers

public class ObjToSchema {

    public static void main(String[] args) throws IOException, JAXBException {
        // TODO Auto-generated method stub
        (JAXBContext.newInstance(Bookdata.class)).generateSchema(new DataSchemaOutputResolver());
    }
}


public class DataSchemaOutputResolver extends SchemaOutputResolver {
    @Override
    public Result createOutput(String arg0, String arg1) throws IOException {
        // TODO Auto-generated method stub
        return new StreamResult(new File("d:/data.xsd"));
    }
}

Hope this will solve your issue.

like image 65
Robin Dhiman Avatar answered Jun 17 '26 08:06

Robin Dhiman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!