JAXB SchemaFactory源命令必须遵循模式之间的导入顺序吗? [英] JAXB SchemaFactory source order must follow import order between schemas?
问题描述
使用最新的JAXB(Sun)并具有模式层次结构,这些模式在模式之间使用导入指令来共享类型定义。在JAXB中对Marshaller / Unmarshaller的setSchema调用中激活了模式验证,这应该将验证推迟到Xerces(使用Java 1.5)。在使用SchemaFactory创建Schema对象时,我不想知道模式之间的import指令的顺序。不幸的是,我还没有找到允许这个的Xerces功能/属性。例如,如果使用导入将a.xsd拉入b.xsd,则以下代码不起作用:
Using latest JAXB (Sun) and have a hierarchy of schemas that use import directives between schemas to share type definitions. Schema validation is activated on the setSchema call to Marshaller/Unmarshaller in JAXB which should defer validation to Xerces (using Java 1.5). I don't want to know the order of import directives between schemas when creating the Schema object with SchemaFactory. Unfortunately, I haven't found a Xerces feature/property that allows for this. For example, if a.xsd is pulled into b.xsd with an import then the following code doesn't work:
FileInputStream a = new FileInputStream("a.xsd");
FileInputStream b = new FileInputStream("b.xsd");
Schema schema = SchemaFactory.newInstance(
XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(
new Source[] {
new StreamSource(b),
new StreamSource(a)
}
);
源数组的顺序必须是a.xsd,然后是b.xsd。有什么方法吗?
The order of the Source array has to be a.xsd then b.xsd. Any way around this?
推荐答案
如果在根源上创建架构,然后将ResourceResolver(LSResourceResolver)设置为在模式创建期间解析其他导入的模式。
What if you create a schema on the root Source, and then set a ResourceResolver (LSResourceResolver) to resolve the other imported schemas during the schema creation.
这篇关于JAXB SchemaFactory源命令必须遵循模式之间的导入顺序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!