非常概括和简化的场景描述:
A very generalized and simplified scenario description:
- 应用程序通过UI构建JAXB实例,
- JAXB实例构建在最后组成的不同步骤中,
- 完成后,我必须对XSD执行每个步骤中创建的JAXB实例的验证,以验证UI层不构建废话。
现在架构定义了复杂类型A,B和C.模式指定XML文档必须具有顶级元素A,这可以包含多个B,这可以选择包含C.我为B创建JAXB实例,并且绝对希望在将它嵌套到A之前对XSD中的复杂类型定义进行验证。但是如果验证这个将失败,如果我验证了整个XSD。
Now the schema defines complex types A, B and C. The schema specifies that XML document must have top level element A and this can contain multiple B and this can optionally include C. I create JAXB instance for B and absolutely want to validate this against the complex type definition in the XSD before nesting it under A. However validation of this will fail if I validate against the entire XSD.
问题:如何仅针对生成其类的XSD的一部分验证JAXB实例来自?
Questions: How to validate JAXB instance against only a part of the XSD from which its class has been generated from?
如何使用sch emagen从JAXB类生成模式,我要验证哪个实例然后验证它?你认为那可行吗?还有其他想法吗?
How about using schemagen to generate schema from the JAXB class which instance I want to validate and then validate against that? Do you think that can work? Any other ideas?
我以前没有使用schemagen的经验,很快就会开始对这个解决方案进行原型设计。
注意:实际上,模式并不像上面的例子那么简单,并且创建一些总是有效的模拟A的解决方案是不可行的选项。更不用说这种验证至少可以说是百位。
推荐答案创建单独的模式对于要验证的元素,此元素位于根级别。 解决方法缺少@xmlRoottag请参阅 101使用JAXB编组对象的方法
create separate schema for element you want to validate, where this element is on root level. to workaround missing @xmlRoottag see 101 ways to marshal objects with JAXB
更多推荐
JAXB和使用schemagen对模式的部分进行验证?
发布评论