元素 'assert' 无效、放错位置或出现太频繁

Element 'assert' is invalid, misplaced, or occurs too often

供应商向我们提供了一组架构(我们也已提醒他们注意错误)。
当我尝试使用 xjc 生成 Java 类 时,它失败并显示以下错误

C:\Users\...>"C:\Program Files (x86)\Java\jdk1.7.0_80\bin\xjc.exe" -d output ICSv1.01.xsd

正在解析模式...

[ERROR] s4s-elt-invalid-content.1: The content of 'ICSBatchV01' is invalid. Element 'assert' is invalid, misplaced, or occurs too often. line 77 of file:/C:/Users/.../ICSv1.01.xsd

[ERROR] s4s-elt-invalid-content.1: The content of 'ICSDocBody' is invalid. Element 'assert' is invalid, misplaced, or occurs too often. line 215 of file:/C:/Users/.../ICSv1.01.xsd

Failed to parse a schema.

我也尝试了 java 8,以及最新最好的 jaxb(java dist 之外)

然而,它确实可以与 Altova 的 xmlspy 软件一起使用,但试图避免供应商 lock-in/non 标准的东西。
我在这里和网上做了一些搜索(主要是在这里)

这里是header。

<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSpy v2015 rel. 4 sp1 (x64) (http://www.altova.com)  -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"     xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" xmlns:msg01="urn:cccc:tech:xsd:ics.msg01.001" xmlns:msg02="urn:cccc:tech:xsd:ics.msg02.001" xmlns:msg03="urn:cccc:tech:xsd:ics.msg03.001" xmlns:msg04="urn:cccc:tech:xsd:ics.msg04.001" xmlns:msg05="urn:cccc:tech:xsd:ics.msg05.001" xmlns:msg06="urn:cccc:tech:xsd:ics.msg06.001" xmlns:msg07="urn:cccc:tech:xsd:ics.msg07.001" xmlns:msg08="urn:cccc:tech:xsd:ics.msg08.001" xmlns:msg09="urn:cccc:tech:xsd:ics.msg09.001" xmlns:msg11="urn:cccc:tech:xsd:ics.msg11.001" xmlns:msg12="urn:cccc:tech:xsd:ics.msg12.001" xmlns:msg13="urn:cccc:tech:xsd:ics.msg13.001" xmlns:msg14="urn:cccc:tech:xsd:ics.msg14.001" xmlns:msq01="urn:cccc:tech:xsd:ics.msq01.001" xmlns:msq02="urn:cccc:tech:xsd:ics.msq02.001" xmlns:msq03="urn:cccc:tech:xsd:ics.msq03.001" xmlns:msq04="urn:cccc:tech:xsd:ics.msq04.001" xmlns:msq05="urn:cccc:tech:xsd:ics.msq05.001" xmlns:msf01="urn:cccc:tech:xsd:ics.msf01.001" xmlns:msf02="urn:cccc:tech:xsd:ics.msf02.001" xmlns:msf03="urn:cccc:tech:xsd:ics.msf03.001" xmlns:msf04="urn:cccc:tech:xsd:ics.msf04.001" xmlns:mss01="urn:cccc:tech:xsd:ics.mss01.001" xmlns:mss02="urn:cccc:tech:xsd:ics.mss02.001" xmlns:mss03="urn:cccc:tech:xsd:ics.mss03.001" xmlns:mss04="urn:cccc:tech:xsd:ics.mss04.001" xmlns:msp01="urn:cccc:tech:xsd:ics.msp01.001" xmlns:msp02="urn:cccc:tech:xsd:ics.msp02.001" xmlns:msp03="urn:cccc:tech:xsd:ics.msp03.001" xmlns:msp04="urn:cccc:tech:xsd:ics.msp04.001" xmlns:doc="urn:cccc:tech:xsd:ics.doc.001" xmlns="urn:cccc:tech:xsd:ics.doc.001" targetNamespace="urn:cccc:tech:xsd:ics.doc.001" elementFormDefault="qualified" attributeFormDefault="unqualified" vc:minVersion="1.1">

这是相关的片段。
从第44行开始到第77行结束(xjc convert报第一个错误的地方)

    <xs:complexType name="ICSBatchV01">
    <xs:sequence>
        <xs:element name="DocHdr" type="ICSDocumentHeader"/>
        <xs:element name="DocBody" type="ICSDocBody"/>
    </xs:sequence>
    <xs:assert test="
    (doc:DocHdr/doc:DocTyp='MSG01' and (count(doc:DocBody/msg01:MSG01PmtSubm) = xs:integer(doc:DocHdr/doc:NbOfTxs))) or 
    (doc:DocHdr/doc:DocTyp='MSG02' and (count(doc:DocBody/msg02:MSG02PmtSubmAckNak) = xs:integer(doc:DocHdr/doc:NbOfTxs))) or
    (doc:DocHdr/doc:DocTyp='MSG03' and (count(doc:DocBody/msg03:MSG03TSetRejection)  = xs:integer(doc:DocHdr/doc:NbOfTxs))) or
    (doc:DocHdr/doc:DocTyp='MSG04' and (count(doc:DocBody/msg04:MSG04LocalBankHoliday)  = xs:integer(doc:DocHdr/doc:NbOfTxs))) or
    (doc:DocHdr/doc:DocTyp='MSG05' and (count(doc:DocBody/msg05:MSG05BeneficiaryFraudNotn)  = xs:integer(doc:DocHdr/doc:NbOfTxs))) or
    (doc:DocHdr/doc:DocTyp='MSG06' and (count(doc:DocBody/msg06:MSG06PmtRequest)  = xs:integer(doc:DocHdr/doc:NbOfTxs))) or
    (doc:DocHdr/doc:DocTyp='MSG07' and (count(doc:DocBody/msg07:MSG07PmtResponse)  = xs:integer(doc:DocHdr/doc:NbOfTxs))) or
    (doc:DocHdr/doc:DocTyp='MSG08' and (count(doc:DocBody/msg08:MSG08PmtResponseAckNak)  = xs:integer(doc:DocHdr/doc:NbOfTxs))) or
    (doc:DocHdr/doc:DocTyp='MSG09' and (count(doc:DocBody/msg09:MSG09PmtResponseItemRejection)  = xs:integer(doc:DocHdr/doc:NbOfTxs))) or
    (doc:DocHdr/doc:DocTyp='MSG11' and (count(doc:DocBody/msg11:MSG11SettlementPreventedNotn)  = xs:integer(doc:DocHdr/doc:NbOfTxs))) or
    (doc:DocHdr/doc:DocTyp='MSG12' and (count(doc:DocBody/msg12:MSG12DefaultPmtResponseNotn)  = xs:integer(doc:DocHdr/doc:NbOfTxs))) or
    (doc:DocHdr/doc:DocTyp='MSG13' and (count(doc:DocBody/msg13:MSG13PmtNotn)  = xs:integer(doc:DocHdr/doc:NbOfTxs))) or
    (doc:DocHdr/doc:DocTyp='MSG14' and (count(doc:DocBody/msg14:MSG14PmtFrdStsUp)  = xs:integer(doc:DocHdr/doc:NbOfTxs))) or
    (doc:DocHdr/doc:DocTyp='MSQ01' and (count(doc:DocBody/msq01:MSQ01QueryMessage)  = xs:integer(doc:DocHdr/doc:NbOfTxs))) or
    (doc:DocHdr/doc:DocTyp='MSQ02' and (count(doc:DocBody/msq02:MSQ02QuerySubmAckNak)  = xs:integer(doc:DocHdr/doc:NbOfTxs))) or
    (doc:DocHdr/doc:DocTyp='MSQ03' and (count(doc:DocBody/msq03:MSQ03QueryRejection)  = xs:integer(doc:DocHdr/doc:NbOfTxs))) or
    (doc:DocHdr/doc:DocTyp='MSQ04' and (count(doc:DocBody/msq04:MSQ04QueryNotn)  = xs:integer(doc:DocHdr/doc:NbOfTxs))) or
    (doc:DocHdr/doc:DocTyp='MSQ05' and (count(doc:DocBody/msq05:MSQ05QuerySettlementPrevented)  = xs:integer(doc:DocHdr/doc:NbOfTxs))) or
    (doc:DocHdr/doc:DocTyp='MSF01' and (count(doc:DocBody/msf01:MSF01FrdSetUnset)  = xs:integer(doc:DocHdr/doc:NbOfTxs))) or
    (doc:DocHdr/doc:DocTyp='MSF02' and (count(doc:DocBody/msf02:MSF02FraudItemSubmAckNak)  = xs:integer(doc:DocHdr/doc:NbOfTxs))) or
    (doc:DocHdr/doc:DocTyp='MSF03' and (count(doc:DocBody/msf03:MSF03FraudItemRejection)  = xs:integer(doc:DocHdr/doc:NbOfTxs))) or
    (doc:DocHdr/doc:DocTyp='MSF04' and (count(doc:DocBody/msf04:MSF04FrdSetUnsetNotn)  = xs:integer(doc:DocHdr/doc:NbOfTxs))) or
    (doc:DocHdr/doc:DocTyp='MSS01' and (count(doc:DocBody/mss01:MSS01StopChq)  = xs:integer(doc:DocHdr/doc:NbOfTxs))) or
    (doc:DocHdr/doc:DocTyp='MSS02' and (count(doc:DocBody/mss02:MSS02StopChqAckNak)  = xs:integer(doc:DocHdr/doc:NbOfTxs))) or
    (doc:DocHdr/doc:DocTyp='MSS03' and (count(doc:DocBody/mss03:MSS03StopChqRejection)  = xs:integer(doc:DocHdr/doc:NbOfTxs))) or
    (doc:DocHdr/doc:DocTyp='MSS04' and (count(doc:DocBody/mss04:MSS04StopChq )  = xs:integer(doc:DocHdr/doc:NbOfTxs))) or
    (doc:DocHdr/doc:DocTyp='MSP01' and (count(doc:DocBody/msp01:MSP01PrevPd)  = xs:integer(doc:DocHdr/doc:NbOfTxs))) or
    (doc:DocHdr/doc:DocTyp='MSP02' and (count(doc:DocBody/msp02:MSP02PrevPdAckNak)  = xs:integer(doc:DocHdr/doc:NbOfTxs))) or
    (doc:DocHdr/doc:DocTyp='MSP03' and (count(doc:DocBody/msp03:MSP03PrevPdRejection)  = xs:integer(doc:DocHdr/doc:NbOfTxs))) or
    (doc:DocHdr/doc:DocTyp='MSP04' and (count(doc:DocBody/msp04:MSP04PrevPd)  = xs:integer(doc:DocHdr/doc:NbOfTxs)))
    ">
        <xs:annotation>
            <xs:documentation>MIG 10.1 NbOfTxs (MWR030): count of messages in document</xs:documentation>
            <xs:documentation>MIG 10.1 DocTyp: code identifying the document content</xs:documentation>
        </xs:annotation>
    </xs:assert>
</xs:complexType>

XSD 1.1 是 xs:assert 所必需的,但 JAXB 仅支持 XSD 1.0,而不支持 XSD 1.1。 None 的添加对 XSD 1.1 支持的请求已得到解决(参考文献:here and here)。

要做什么:

  • 贡献支持自己,或希望别人支持(不太可能)。
  • 与此同时,分析 XSD 的 1.1 依赖项。如果温和, 比如只使用xs:assert,写一个简单的XSLT转换 去除 xs:assert 验证,以便您仍然可以生成 类。 (请参阅下面的 XSLT。)可选地,根据需要实施 xs:assert 检查 在 Java 中手动编码。

要剥离的 XSLT xs:assert:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="xs:assert"/>
</xsl:stylesheet>