How to generate an XML model from a SCHEMA XSD using JAXB?

1

I have a Schema .XSD and would like to generate an XML from this template. Below I have this code, however I am using the JLibs library. I wonder if it's possible to do something like the JAXB library. The XSD file is being passed as a parameter to the makeXmlModel() method.

public static boolean makeXmlModel(File file)
{
    final XSModel xsModel = new XSParser().parse(file.getPath());
    final XSInstance xsInstance = new XSInstance();
    xsInstance.generateOptionalElements = Boolean.TRUE; // null means random
    final QName rootElement = new QName("http://www.portalfiscal.inf.br/nfe", "NFe");
    XMLDocument sampleXml;
    try {
         sampleXml = new XMLDocument(new StreamResult("model_xml.xml"), true, 4, null);
         xsInstance.generate(xsModel, rootElement, sampleXml);
         return true;
     } catch (TransformerConfigurationException e) {
         e.printStackTrace();
         return false;
     } catch (IllegalArgumentException e) {
         return false;
     }
}
    
asked by anonymous 06.03.2015 / 15:51

0 answers