简体   繁体   English

如何将Java JAXB Schema类导出到xsd文件?

[英]How to export java JAXB Schema class to an xsd file?

I'm running into a problem with some XML validation and am trying to debug my problem. 我遇到了一些XML验证问题,并试图调试我的问题。 I am generating my XSDs on the fly with JAXBContext.generateSchema(), and then creating a unified schema with SchemaFactory.newSchema(schemas). 我使用JAXBContext.generateSchema()动态生成XSD,然后使用SchemaFactory.newSchema(schemas)创建统一的架构。 However, my validation is failing. 但是,我的验证失败。 I'd like to see if the unified schema that newSchema is creating is as I expect, however I cannot seem to find a way to export the resulting Schema class to a string or a text file. 我想看看newSchema正在创建的统一模式是否符合我的期望,但是我似乎找不到找到将结果Schema类导出到字符串或文本文件的方法。

Is there any way to export a javax.xml.validation.Schema class into a readable String and/or XSD file? 有什么方法可以将javax.xml.validation.Schema类导出到可读的String和/或XSD文件中? I looked through the API and cannot seem to find anything. 我浏览了API,似乎找不到任何东西。

Thanks, 谢谢,

Eric 埃里克

Instead of combining your schemas after creating them from JAXBContext.generateSchema(), why not just generate them all at once from your JAXBContext. 为什么不从JAXBContext.generateSchema()创建架构后合并架构,为什么不直接从JAXBContext一次生成所有架构呢?

JAXBContext jc = JAXBContext.newInstance( new Class[] { Class1.class,
                                                        Class2.class,
                                                        Class3.class
                                                      }
                                        );
jc.generateSchema(new SchemaOutputResolver() {
    @Override
    public Result createOutput(String namespaceUri, String suggestedFileName) throws IOException {
      File file = new File(suggestedFileName);
      return new StreamResult(file);
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM