我们从供应商那里获得了一组模式(我们也已向他们发出错误警告)。
当我尝试使用 xjc 生成 Java 类时,它失败并显示以下错误
C:\Users\...>"C:\Program Files (x86)\Java\jdk1.7.0_80\bin\xjc.exe" -d output ICSv1.01.xsd
解析模式...
我还尝试了 java 8,以及最新最好的 jaxb(在 java dist 之外)
但是,它确实可以与 Altova 的 xmlspy 软件一起使用,但会尽量避免供应商锁定/非标准的东西。
我在这里和网络上做了一些搜索(主要是在这里)
这是标题。
<?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 转换报告了第一个错误)
<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>
最佳答案
xs:assert
需要 XSD 1.1,但 JAXB 仅支持 XSD 1.0,不支持 XSD 1.1。添加对 XSD 1.1 支持的请求都没有得到解决(引用: here 和 here )。
该怎么办:
比如只使用
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>
关于java - 元素 'assert' 无效、错位或出现太频繁,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34518325/