JAXB和使用schemagen对模式的部分进行验证?

编程入门 行业动态 更新时间:2024-10-23 14:19:35
本文介绍了JAXB和使用schemagen对模式的部分进行验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

非常概括和简化的场景描述:

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对模式的部分进行验证?

本文发布于:2023-06-07 22:02:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/568564.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模式   JAXB   schemagen

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!