java - SAXParseException 列出可选值
问题描述
我在 Windows 10 上运行的 Java 1.8.0_191 程序中收到以下 UnmarshalException,该程序使用使用 jaxb2 Maven 插件版本 2.5.0 生成的类来处理传入的 XML SOAP 请求:
JAXB unmarshalling exception; nested exception is javax.xml.bind.UnmarshalException with linked exception:
[org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 622; cvc-complex-type.2.4.a : Contenu non valide trouvé à partir del'élément 'MotifCommande'. L'une des valeurs '{AliasCde,RefExterneCde, DateDepot}' est attendue.]
这是异常消息的英文快速翻译:
发现以 MotifCommand 项目开头的无效内容。需要项目“{AliasCd, RefExterneCde, DateDepot}”之一。
奇怪的是,项目列表中提到了两个可选字段(AliasCD 和 RefExterneCde)和一个必填字段(DateDepot)。为什么不只是必填字段?
此外,为什么在 XSD 中,尽管 MotifCommande 标记出现在(强制)DateDepot 标记之后,但消息指出内容无效?
XSD 和 SOAP 请求以 zip 格式提供,位于此网站:https ://github.com/highsource/maven-jaxb2-plugin/issues/185
非常感谢您的帮助。
解决方案
错误消息列出了文档中该位置允许的所有元素。这还包括可选元素。如果出现其他任何内容,则为错误。
XML 模式中的相关部分是这样的:
<xsd:sequence>
<xsd:element name="SystemeRefCde" type="xsd:string" minOccurs="1"/>
<xsd:element name="AliasCde" minOccurs="0" maxOccurs="unbounded">
<xsd:element name="RefExterneCde" minOccurs="0" maxOccurs="unbounded">
<xsd:element name="DateDepot" type="xsd:string" minOccurs="1"/>
<!-- ... -->
<xsd:element name="MotifCommande" type="xsd:string" minOccurs="0"/>
您正在使用序列。因此,项目的顺序是相关的。这意味着,SystemeRefCde
仅在 optinoal 元素之后AliasCde
或RefExterneCde
之后,DateDepot
可能会出现强制元素。每个其他元素都会导致架构冲突。
在您的请求中,您有:
<RefCommande>32R69010200004101415</RefCommande>
<SystemeRefCde>32R</SystemeRefCde>
<MotifCommande>ORDST</MotifCommande>
在SystemeRefCde
序列中的下一个元素之后是MotifCommande
。XSD 不允许这样做。您至少缺少DateDepot
介于两者之间的强制性元素。
推荐阅读
- c# - 对 Linq 查询进行排序
- scikit-learn - 在 Colaboratory 中可视化决策树
- python-3.x - 在 python 中读取 OLE 文件元数据
- algorithm - 寻找最优解的动态算法
- ios - Some UIColors are black instead of the way the way they should be, why?
- python - Shutdown with terminal on rising edge of GPIO input
- websphere - NoClassDefFoundError Websphere Applicatoin Server (WAS)(尽管类存在)
- android - ViewCompat$OnUnhandledKeyEventListener on setContentView
- solr - Solr 通过导入/更新和修改数据到 Solr
- sql - SQL:按方向过滤行