javaxmlxsdjaxbrelaxng

Issue using JAXB: [ERROR] Unexpected <xsd:element> appears with an XSD file


I want use JAXB to generate Java Objects from a XSD file and execute a script to marshal some XML with differents data.

Actually, to get my XSD file I've used a program named AGAPE (a french tool to generate SEDA files). This software produces a RNG file and a XSD file. I thought I could use the RNG file translating him to XSD with Jing Trang. But It doesn't seem good, there are some syntax errors(A little weird)...

So I choose to use the XML file which (I think) is mostly an XSD. I just want to create Java Objects from this file using JAXB.

But at the moment I can't because when I run this command :

xjc.exe -nv -d C:\test3 C:\20150907.xsd 

Or 20150907.xml...

I got this message error :

[ERROR] Unexpected <xsd:element> appears at line 10 column 57
ligne 10 sur file:/C:/20150907.xml
Echec de lanalyse dun schéma.

Or

[ERROR] Unexpected <xsd:element> appears at line 10 column 57
ligne 10 sur file:/C:/20150907.xsd
Echec de lanalyse dun schéma.

So I really hope that someone could help me.

Here my XML/XSD file:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="fr:gouv:ae:archive:draft:standard_echange_v0.2"
            xmlns:qdt="fr:gouv:ae:archive:draft:standard_echange_v0.2:QualifiedDataType:1"
            xmlns:udt="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:6" attributeFormDefault="unqualified"
            elementFormDefault="qualified" targetNamespace="fr:gouv:ae:archive:draft:standard_echange_v0.2"
            version="1.1">

    <xsd:element name="ArchiveTransfer">
        <xsd:element fixed="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" minOccurs="0"
                     name="Comment" type="udt:TextType">
            <xsd:attribute name="languageID" type="xsd:language" use="prohibited"/>
        </xsd:element>
        <xsd:element fixed="2015-09-07T00:00:00.0Z" name="Date" type="udt:DateTimeType">
            <xsd:annotation>Date du dépôt</xsd:annotation>
        </xsd:element>
        <xsd:element name="TransferIdentifier" type="qdt:ArchivesIDType">
            <xsd:attribute name="schemeID" type="xsd:token" use="prohibited"/>
            <xsd:attribute name="schemeName" type="xsd:string" use="prohibited"/>
            <xsd:attribute name="schemeAgencyName" type="xsd:string" use="prohibited"/>
            <xsd:attribute name="schemeVersionID" type="xsd:token" use="prohibited"/>
            <xsd:attribute name="schemeDataURI" type="xsd:anyURI" use="prohibited"/>
            <xsd:attribute name="schemeURI" type="xsd:anyURI" use="prohibited"/>
            <xsd:annotation>Idfentifiant Unique attribué par Mnesys</xsd:annotation>
        </xsd:element>
        <xsd:element name="TransferringAgency" type="OrganizationType">
            <xsd:element fixed="XXXXXXXXXXXXXXXXXXX" name="Identification" type="qdt:ArchivesIDType">
                <xsd:attribute name="schemeID" type="xsd:token" use="prohibited"/>
                <xsd:attribute name="schemeName" type="xsd:string" use="prohibited"/>
                <xsd:attribute name="schemeAgencyName" type="xsd:string" use="prohibited"/>
                <xsd:attribute name="schemeVersionID" type="xsd:token" use="prohibited"/>
                <xsd:attribute name="schemeDataURI" type="xsd:anyURI" use="prohibited"/>
                <xsd:attribute name="schemeURI" type="xsd:anyURI" use="prohibited"/>
            </xsd:element>
            <xsd:element fixed="Banctec" minOccurs="1" name="Name" type="udt:TextType">
                <xsd:attribute name="languageID" type="xsd:language" use="prohibited"/>
            </xsd:element>
        </xsd:element>
        <xsd:element name="ArchivalAgency" type="OrganizationType">
            <xsd:element fixed="YYYYYY" name="Identification" type="qdt:ArchivesIDType">
                <xsd:attribute name="schemeID" type="xsd:token" use="prohibited"/>
                <xsd:attribute name="schemeName" type="xsd:string" use="prohibited"/>
                <xsd:attribute name="schemeAgencyName" type="xsd:string" use="prohibited"/>
                <xsd:attribute name="schemeVersionID" type="xsd:token" use="prohibited"/>
                <xsd:attribute name="schemeDataURI" type="xsd:anyURI" use="prohibited"/>
                <xsd:attribute name="schemeURI" type="xsd:anyURI" use="prohibited"/>
            </xsd:element>
            <xsd:element fixed=" XXXXXXX" minOccurs="0" name="Name"
                         type="udt:TextType">
                <xsd:attribute name="languageID" type="xsd:language" use="prohibited"/>
            </xsd:element>
        </xsd:element>
        <xsd:element maxOccurs="1" minOccurs="1" name="Integrity" type="HashCodeType"/>
        <xsd:element maxOccurs="unbounded" name="Contains" type="ArchiveType">
            <xsd:element fixed="ZZZZZZZZZZZZZZZ" minOccurs="1" name="ArchivalAgreement" type="qdt:ArchivesIDType">
                <xsd:attribute name="schemeID" type="xsd:token" use="prohibited"/>
                <xsd:attribute name="schemeName" type="xsd:string" use="prohibited"/>
                <xsd:attribute name="schemeAgencyName" type="xsd:string" use="prohibited"/>
                <xsd:attribute name="schemeVersionID" type="xsd:token" use="prohibited"/>
                <xsd:attribute name="schemeDataURI" type="xsd:anyURI" use="prohibited"/>
                <xsd:attribute name="schemeURI" type="xsd:anyURI" use="prohibited"/>
            </xsd:element>
            <xsd:element fixed="AAAAAAA" minOccurs="0" name="ArchivalProfile" type="qdt:ArchivesIDType">
                <xsd:attribute name="schemeID" type="xsd:token" use="prohibited"/>
                <xsd:attribute name="schemeName" type="xsd:string" use="prohibited"/>
                <xsd:attribute name="schemeAgencyName" type="xsd:string" use="prohibited"/>
                <xsd:attribute name="schemeVersionID" type="xsd:token" use="prohibited"/>
                <xsd:attribute name="schemeDataURI" type="xsd:anyURI" use="prohibited"/>
                <xsd:attribute name="schemeURI" type="xsd:anyURI" use="prohibited"/>
            </xsd:element>
            <xsd:element fixed="fr" maxOccurs="1" name="DescriptionLanguage" type="qdt:CodeLanguageType">
                <xsd:attribute fixed="edition 2009" name="listVersionID" type="xsd:token" use="required"/>
            </xsd:element>
            <xsd:element fixed="series" name="DescriptionLevel" type="qdt:CodeDescriptionLevelType">
                <xsd:attribute fixed="edition 2009" name="listVersionID" type="xsd:token" use="required"/>
            </xsd:element>
            <xsd:element fixed="AAAAAAAAAAAAAAAAAAAAAAA" name="Name" type="udt:TextType">
                <xsd:attribute name="languageID" type="xsd:language" use="prohibited"/>
            </xsd:element>
            <xsd:element name="ContentDescription" type="ContentDescriptionType">
                <xsd:attribute name="Id" type="xsd:ID" use="prohibited"/>
                <xsd:element fixed="ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ" minOccurs="1"
                             name="Description" type="udt:TextType">
                    <xsd:attribute name="languageID" type="xsd:language" use="prohibited"/>
                </xsd:element>
                <xsd:element fixed="AAAAAAAAAAAAAAA" maxOccurs="1" minOccurs="1" name="FilePlanPosition"
                             type="qdt:ArchivesIDType">
                    <xsd:attribute name="schemeID" type="xsd:token" use="prohibited"/>
                    <xsd:attribute name="schemeName" type="xsd:string" use="prohibited"/>
                    <xsd:attribute name="schemeAgencyName" type="xsd:string" use="prohibited"/>
                    <xsd:attribute name="schemeVersionID" type="xsd:token" use="prohibited"/>
                    <xsd:attribute name="schemeDataURI" type="xsd:anyURI" use="prohibited"/>
                    <xsd:attribute name="schemeURI" type="xsd:anyURI" use="prohibited"/>
                </xsd:element>
                <xsd:element fixed="EEEEEEEEEEEEE" maxOccurs="1" minOccurs="1" name="FilePlanPosition"
                             type="qdt:ArchivesIDType">
                    <xsd:attribute name="schemeID" type="xsd:token" use="prohibited"/>
                    <xsd:attribute name="schemeName" type="xsd:string" use="prohibited"/>
                    <xsd:attribute name="schemeAgencyName" type="xsd:string" use="prohibited"/>
                    <xsd:attribute name="schemeVersionID" type="xsd:token" use="prohibited"/>
                    <xsd:attribute name="schemeDataURI" type="xsd:anyURI" use="prohibited"/>
                    <xsd:attribute name="schemeURI" type="xsd:anyURI" use="prohibited"/>
                </xsd:element>
                <xsd:element maxOccurs="1" minOccurs="1" name="Format" type="udt:TextType">
                    <xsd:attribute name="languageID" type="xsd:language" use="prohibited"/>
                    <xsd:annotation>PDF</xsd:annotation>
                </xsd:element>
                <xsd:element fixed="fr" maxOccurs="1" name="Language" type="qdt:CodeLanguageType">
                    <xsd:attribute fixed="edition 2009" name="listVersionID" type="xsd:token" use="required"/>
                </xsd:element>
                <xsd:element fixed="2015-09-07" minOccurs="1" name="OldestDate" type="udt:DateType">
                    <xsd:annotation>Date de transfert</xsd:annotation>
                </xsd:element>
            </xsd:element>
            <xsd:attribute name="Id" type="xsd:ID" use="prohibited"/>
            <xsd:element maxOccurs="1" minOccurs="1" name="Appraisal" type="AppraisalRulesType">
                <xsd:attribute name="Id" type="xsd:ID" use="prohibited"/>
                <xsd:element fixed="conserver" name="Code" type="qdt:CodeAppraisalType">
                    <xsd:attribute fixed="edition 2009" name="listVersionID" type="xsd:token" use="required"/>
                </xsd:element>
                <xsd:element fixed="P30Y" name="Duration" type="qdt:ArchivesDurationType"/>
                <xsd:element fixed="2015-09-07" name="StartDate" type="udt:DateType">
                    <xsd:annotation>Date de transfert</xsd:annotation>
                </xsd:element>
            </xsd:element>
            <xsd:element maxOccurs="1" minOccurs="1" name="AccessRestriction" type="AccessRestrictionRulesType">
                <xsd:attribute name="Id" type="xsd:ID" use="prohibited"/>
                <xsd:element fixed="AR061" name="Code" type="qdt:CodeAccessRestrictionType">
                    <xsd:attribute fixed="edition 2009" name="listVersionID" type="xsd:token" use="required"/>
                </xsd:element>
                <xsd:element fixed="2015-09-07" name="StartDate" type="udt:DateType">
                    <xsd:annotation>Date de transfert</xsd:annotation>
                </xsd:element>
            </xsd:element>
            <xsd:element maxOccurs="unbounded" minOccurs="0" name="Contains" type="ArchiveObjectType">
                <xsd:attribute name="Id" type="xsd:ID" use="prohibited"/>
                <xsd:element fixed="series" name="DescriptionLevel" type="qdt:CodeDescriptionLevelType">
                    <xsd:attribute fixed="edition 2009" name="listVersionID" type="xsd:token" use="required"/>
                </xsd:element>
                <xsd:element fixed="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" name="Name"
                             type="udt:TextType">
                    <xsd:attribute name="languageID" type="xsd:language" use="prohibited"/>
                </xsd:element>
                <xsd:element maxOccurs="unbounded" minOccurs="0" name="Document" type="DocumentType">
                    <xsd:attribute name="Id" type="xsd:ID" use="prohibited"/>
                    <xsd:element name="Attachment" type="qdt:ArchivesBinaryObjectType">
                        <xsd:attribute name="format" type="clmDAFFileTypeCode:FileTypeCodeType" use="prohibited"/>
                        <xsd:attribute name="mimeCode" type="clmIANAMIMEMediaType:MIMEMediaTypeContentType"
                                       use="prohibited"/>
                        <xsd:attribute name="encodingCode" type="clm60133:CharacterSetEncodingCodeContentType"
                                       use="prohibited"/>
                        <xsd:attribute name="characterSetCode"
                                       type="clmIANACharacterSetCode:CharacterSetCodeContentType" use="prohibited"/>
                        <xsd:attribute name="uri" type="xsd:anyURI" use="prohibited"/>
                        <xsd:attribute name="filename" type="xsd:string" use="prohibited"/>
                        <xsd:annotation>Objet-données (contenu binaire ou fichier joint)</xsd:annotation>
                    </xsd:element>
                    <xsd:element fixed="CDO" name="Type" type="qdt:CodeDocumentType">
                        <xsd:attribute fixed="edition 2009" name="listVersionID" type="xsd:token" use="required"/>
                    </xsd:element>
                </xsd:element>
            </xsd:element>
        </xsd:element>
        <xsd:attribute name="Id" type="xsd:ID" use="prohibited"/>
    </xsd:element>

</xsd:schema>

And just in case where you prefer the RNG format I link the RNG file.

<?xml version="1.0" encoding="UTF-8"?>
<rng:grammar xmlns:rng="http://relaxng.org/ns/structure/1.0"
             xmlns:udt="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:6"
             xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
             xmlns:qdt="fr:gouv:ae:archive:draft:standard_echange_v0.2:QualifiedDataType:1"
             xmlns:ccts="urn:un:unece:uncefact:documentation:standard:CoreComponentsTechnicalSpecification:2"
             xmlns="fr:gouv:ae:archive:draft:standard_echange_v0.2" ns="fr:gouv:ae:archive:draft:standard_echange_v0.2"
             datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
    <jaxb:schemaBindings>
        <jaxb:package name="com.acme.foo"/>
    </jaxb:schemaBindings>
    <rng:start combine="choice">
        <rng:ref name="ArchiveTransfer"/>
    </rng:start>
    <rng:define name="ArchiveTransfer">
        <rng:element name="ArchiveTransfer">
            <rng:ref name="ArchiveTransfer_N65537"/>
        </rng:element>
    </rng:define>
    <rng:define name="ArchiveTransfer_N65537">
        <rng:optional>
            <rng:element name="Comment">
                <rng:ref name="Comment_N65541"/>
            </rng:element>
        </rng:optional>
        <rng:element name="Date">
            <rng:value>2015-09-07T00:00:00.0Z</rng:value>
        </rng:element>
        <rng:element name="TransferIdentifier">
            <rng:ref name="TransferIdentifier_N65562"/>
        </rng:element>
        <rng:element name="TransferringAgency">
            <rng:ref name="TransferringAgency_N65594"/>
        </rng:element>
        <rng:element name="ArchivalAgency">
            <rng:ref name="ArchivalAgency_N65640"/>
        </rng:element>
        <rng:element name="Integrity">
            <rng:ref name="anyElement"/>
        </rng:element>
        <rng:oneOrMore>
            <rng:element name="Contains">
                <rng:ref name="Contains_N65694"/>
            </rng:element>
        </rng:oneOrMore>
    </rng:define>
    <rng:define name="TransferringAgency_N65594">
        <rng:element name="Identification">
            <rng:ref name="Identification_N65597"/>
        </rng:element>
        <rng:element name="Name">
            <rng:ref name="Name_N65628"/>
        </rng:element>
    </rng:define>
    <rng:define name="ArchivalAgency_N65640">
        <rng:element name="Identification">
            <rng:ref name="Identification_N65643"/>
        </rng:element>
        <rng:optional>
            <rng:element name="Name">
                <rng:ref name="Name_N65674"/>
            </rng:element>
        </rng:optional>
    </rng:define>
    <rng:define name="Contains_N65694">
        <rng:element name="ArchivalAgreement">
            <rng:ref name="ArchivalAgreement_N65698"/>
        </rng:element>
        <rng:optional>
            <rng:element name="ArchivalProfile">
                <rng:ref name="ArchivalProfile_N65730"/>
            </rng:element>
        </rng:optional>
        <rng:element name="DescriptionLanguage">
            <rng:ref name="DescriptionLanguage_N65762"/>
        </rng:element>
        <rng:element name="DescriptionLevel">
            <rng:ref name="DescriptionLevel_N65775"/>
        </rng:element>
        <rng:element name="Name">
            <rng:ref name="Name_N65787"/>
        </rng:element>
        <rng:element name="ContentDescription">
            <rng:ref name="ContentDescription_N65798"/>
        </rng:element>
        <rng:element name="Appraisal">
            <rng:ref name="Appraisal_N65923"/>
        </rng:element>
        <rng:element name="AccessRestriction">
            <rng:ref name="AccessRestriction_N65963"/>
        </rng:element>
        <rng:zeroOrMore>
            <rng:element name="Contains">
                <rng:ref name="Contains_N65996"/>
            </rng:element>
        </rng:zeroOrMore>
    </rng:define>
    <rng:define name="ContentDescription_N65798">
        <rng:element name="Description">
            <rng:ref name="Description_N65801"/>
        </rng:element>
        <rng:element name="FilePlanPosition">
            <rng:ref name="FilePlanPosition_N65813"/>
        </rng:element>
        <rng:element name="FilePlanPosition">
            <rng:ref name="FilePlanPosition_N65846"/>
        </rng:element>
        <rng:element name="Format">
            <rng:ref name="Format_N65879"/>
        </rng:element>
        <rng:element name="Language">
            <rng:ref name="Language_N65893"/>
        </rng:element>
        <rng:element name="OldestDate">
            <rng:value>2015-09-07</rng:value>
        </rng:element>
    </rng:define>
    <rng:define name="Appraisal_N65923">
        <rng:element name="Code">
            <rng:ref name="Code_N65928"/>
        </rng:element>
        <rng:element name="Duration">
            <rng:value>P30Y</rng:value>
        </rng:element>
        <rng:element name="StartDate">
            <rng:value>2015-09-07</rng:value>
        </rng:element>
    </rng:define>
    <rng:define name="AccessRestriction_N65963">
        <rng:element name="Code">
            <rng:ref name="Code_N65968"/>
        </rng:element>
        <rng:element name="StartDate">
            <rng:value>2015-09-07</rng:value>
        </rng:element>
    </rng:define>
    <rng:define name="Contains_N65996">
        <rng:element name="DescriptionLevel">
            <rng:ref name="DescriptionLevel_N66001"/>
        </rng:element>
        <rng:element name="Name">
            <rng:ref name="Name_N66013"/>
        </rng:element>
        <rng:zeroOrMore>
            <rng:element name="Document">
                <rng:ref name="Document_N66024"/>
            </rng:element>
        </rng:zeroOrMore>
    </rng:define>
    <rng:define name="Document_N66024">
        <rng:element name="Attachment">
            <rng:ref name="Attachment_N66029"/>
        </rng:element>
        <rng:element name="Type">
            <rng:ref name="Type_N66061"/>
        </rng:element>
    </rng:define>
    <rng:define name="Comment_N65541">
        <rng:value>AAAAAAAAAAAAAAAAA</rng:value>
    </rng:define>
    <rng:define name="TransferIdentifier_N65562">
        <rng:data type="string"/>
    </rng:define>
    <rng:define name="Identification_N65597">
        <rng:value>XXXXXXXXXXXXXXXXXXX</rng:value>
    </rng:define>
    <rng:define name="Name_N65628">
        <rng:value>Banctec</rng:value>
    </rng:define>
    <rng:define name="Identification_N65643">
        <rng:value>YYYYYYYYYYYYYYYYYYY</rng:value>
    </rng:define>
    <rng:define name="Name_N65674">
        <rng:value>SAAAAAAAAAAAAAAAAAAAAA</rng:value>
    </rng:define>
    <rng:define name="ArchivalAgreement_N65698">
        <rng:value>NNNNNNNNNNNNNNNNNNNNNNN</rng:value>
    </rng:define>
    <rng:define name="ArchivalProfile_N65730">
        <rng:value>PMMMMMMMMMMMMMMMMMMMMMMMMMMMMM</rng:value>
    </rng:define>
    <rng:define name="DescriptionLanguage_N65762">
        <rng:value>fr</rng:value>
        <rng:attribute name="listVersionID">
            <rng:value>edition 2009</rng:value>
        </rng:attribute>
    </rng:define>
    <rng:define name="DescriptionLevel_N65775">
        <rng:value>series</rng:value>
        <rng:attribute name="listVersionID">
            <rng:value>edition 2009</rng:value>
        </rng:attribute>
    </rng:define>
    <rng:define name="Name_N65787">
        <rng:value>AAAAAAAAAAAAAAAAAAAAAA</rng:value>
    </rng:define>
    <rng:define name="Description_N65801">
        <rng:value>AAAAAAAAAAAAAAAAAAAAAAAAAAAA</rng:value>
    </rng:define>
    <rng:define name="FilePlanPosition_N65813">
        <rng:value>BBBBBBBBBBBBBBBBB</rng:value>
    </rng:define>
    <rng:define name="FilePlanPosition_N65846">
        <rng:value>CCCCCCCCCCCCCCCCCCCCCCC</rng:value>
    </rng:define>
    <rng:define name="Format_N65879">
        <rng:data type="string"/>
    </rng:define>
    <rng:define name="Language_N65893">
        <rng:value>fr</rng:value>
        <rng:attribute name="listVersionID">
            <rng:value>edition 2009</rng:value>
        </rng:attribute>
    </rng:define>
    <rng:define name="Code_N65928">
        <rng:value>conserver</rng:value>
        <rng:attribute name="listVersionID">
            <rng:value>edition 2009</rng:value>
        </rng:attribute>
    </rng:define>
    <rng:define name="Code_N65968">
        <rng:value>AR061</rng:value>
        <rng:attribute name="listVersionID">
            <rng:value>edition 2009</rng:value>
        </rng:attribute>
    </rng:define>
    <rng:define name="DescriptionLevel_N66001">
        <rng:value>series</rng:value>
        <rng:attribute name="listVersionID">
            <rng:value>edition 2009</rng:value>
        </rng:attribute>
    </rng:define>
    <rng:define name="Name_N66013">
        <rng:value>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA</rng:value>
    </rng:define>
    <rng:define name="Attachment_N66029">
        <rng:data type="string"/>
    </rng:define>
    <rng:define name="Type_N66061">
        <rng:value>CDO</rng:value>
        <rng:attribute name="listVersionID">
            <rng:value>edition 2009</rng:value>
        </rng:attribute>
    </rng:define>
    <rng:define name="anyElement">
        <rng:zeroOrMore>
            <rng:element>
                <rng:anyName/>
                <rng:zeroOrMore>
                    <rng:choice>
                        <rng:attribute>
                            <rng:anyName/>
                        </rng:attribute>
                        <rng:text/>
                        <rng:ref name="anyElement"/>
                    </rng:choice>
                </rng:zeroOrMore>
            </rng:element>
        </rng:zeroOrMore>
    </rng:define>
</rng:grammar>

Solution

  • If you run your XSD in oXygen, Xerces shows a more informative issue:

    Engine name: Xerces
    Severity: error
    Description: s4s-elt-must-match.1: The content of 'ArchiveTransfer' must match (annotation?, (simpleType | complexType)?, (unique | key | keyref)*)). A problem was found starting at: element.

    And shows that you have an xsd:element following an xsd:element. Since this is repeated a bunch of times, removing this element won't help. You will need to carefully reconsider the design, for instance, something along those lines (not ideal, but may work for your case):

    <xsd:element name="ArchiveTransfer" >    
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="test1"></xsd:element>
                <xsd:element name="test2"></xsd:element>
                <xsd:element name="test3"></xsd:element>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
    

    Consider using one of the many XSD design tools around to graphically design your XSD so you don't have to worry about these kinds of syntax errors.

    Next to that, Xerces showed a whole bunch of other errors, but first things first.

    JABX won't be able to use the XSD until it is fixed.