在下面的代码中,我正在使用JLibs库从Schema XSD生成一个xml文件。我的问题是,如何使用库JAXB?
参数“文件”是XSD文件。
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) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
} catch (IllegalArgumentException e) {
return false;
}
}