java - SchemaCompiler bind() 返回 null

标签 java xsd jaxb xjc

我正在编写一个类来在 java 中运行 xjc。我的代码如下:

SchemaCompiler sc = XJC.createSchemaCompiler();
 URL url = new URL("file://E:\\JAXB\\books.xsd");
 sc.parseSchema(new InputSource(url.toExternalForm()));
 S2JJAXBModel model = sc.bind();
 JCodeModel cm = model.generateCode(null, null);
 cm.build(new FileCodeWriter(new File("E:\\JAXBTest")));

当我运行这个时,我得到的模型为空。

任何人都可以帮助我或提供任何我可以了解这一点的链接。

最佳答案

如果您查看 SchemaCompiler API 中的 bind() 方法,它会显示:

bind() returns null if the compilation fails. The errors should have been delivered to the registered error handler in such a case.

因此,您需要使用 SchemaCompiler.setErrorListener() 注册一个错误监听器,如下所示:

sc.setErrorListener(new ErrorListener(){
  public void error(SAXParseException exception){
    exception.printStackTrace();
  }
});

希望您能获得有关问题所在的更多信息。

关于java - SchemaCompiler bind() 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4562324/

相关文章:

Java返回返回空白

xml模式检查限制枚举值只出现一次

java - 使用 hibernate (JAVA) 时如何避免 "mysql"数据库中出现重复项?

java - 无法在 JDBC PreparedStatement 的单引号内转义参数

java - 显示 org.eclipse.xsd.XSDSchema 内容

C# 使用 XSD 架构作为表单的元数据

java - JAXB 解码派生类型

java - XML 到 JAXB 的绑定(bind)是否具有嵌套元素?

java - 使用 Exception Missing Envelope 标签的 Spring Web 服务模板

java - Spring 安全 SAML : Extract Attributes from a saml2p:Response as user attributes