【发布时间】:2014-06-04 13:29:22
【问题描述】:
我正在尝试按照本文Is it possible to generate a XSD from a JAXB-annotated class中提到的代码从Java Annotated 类生成XSD
JAXBContext jaxbContext = JAXBContext.newInstance(Customer.class);
SchemaOutputResolver sor = new MySchemaOutputResolver();
jaxbContext.generateSchema(sor);
public 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;
}
}
此技术使用文件系统,我的要求是在不使用文件系统的情况下将 XML 作为字符串。
SchemaOutputResolver 的实现是否有可能不会将文件写入磁盘并返回或设置一些带有字符串值的实例变量。
【问题讨论】: