We were provided a set of schemas from a vendor, (we have alerted them to the error as well).
When I try to generate the Java classes using xjc, it fails with the error below
C:\Users\...>"C:\Program Files (x86)\Java\jdk1.7.0_80\bin\xjc.exe" -d output ICSv1.01.xsd
parsing a schema...
[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.
I also tried java 8, and the latest and greatest jaxb (outside of java dist)
However, it does work with Altova's xmlspy software, but trying to avoid vendor lock-in/non standard stuff.
I did some searching here and the web (mostly here)
Here is the 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">
Here is the relevant snippet.
Starting at line 44 and ending at line 77 (where the xjc convert reported the first error)
<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 is required for xs:assert
, but JAXB only supports XSD 1.0, not XSD 1.1. None of the requests to add support for XSD 1.1 have be addressed (references: here and here).
What to do:
- Contribute support yourself, or hope that someone else does (unlikely).
- In the meantime, analyse the XSDs for 1.1 dependencies. If mild,
such as only use of
xs:assert
, write a simple XSLT transformation to stripxs:assert
validations so that you can still generate classes. (See XSLT below.) Optionally, as needed, implement thexs:assert
checks in Java code manually.
XSLT to strip 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>
来源:https://stackoverflow.com/questions/34518325/element-assert-is-invalid-misplaced-or-occurs-too-often