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;
}
}