JAXB/XJC - XML Schema Parsin Fail

别来无恙 提交于 2019-12-25 09:01:24

问题


I am currently working with JAXB (and its tool XJC) to "translate" an XML Schema (.xsd) to auto-generated java classes.

I execute the following command :

java -jar "../lib/com.sun.jaxb_1.0.0/jaxb-xjc.jar" schema.xsd

But, obviously, I don't get to compile my schema and get the following errors :

parsing a schema...
[ERROR] s4s-elt-invalid-content.1 : Le contenu de 'heureType' n'est pas valide. L'élément 'element' n'est pas valide, est mal placé ou compte trop d'occurrences.
line 9 of file:***/Workspace_XML/fichier_cri/schema.xsd

[ERROR] s4s-elt-invalid-content.1 : Le contenu de 'demandeCri' n'est pas valide. L'élément 'element' n'est pas valide, est mal placé ou compte trop d'occurrences.
line 24 of file:***/Workspace_XML/fichier_cri/schema.xsd

[ERROR] s4s-elt-invalid-content.1 : Le contenu de 'infoCri' n'est pas valide. L'élément 'element' n'est pas valide, est mal placé ou compte trop d'occurrences.
line 28 of file:***/Workspace_XML/fichier_cri/schema.xsd

[ERROR] s4s-elt-invalid-content.1 : Le contenu de 'criType' n'est pas valide. L'élément 'element' n'est pas valide, est mal placé ou compte trop d'occurrences.
line 33 of file:***/Workspace_XML/fichier_cri/schema.xsd

[ERROR] s4s-elt-invalid-content.1 : Le contenu de 'initLiaison' n'est pas valide. L'élément 'element' n'est pas valide, est mal placé ou compte trop d'occurrences.
line 46 of file:***/Workspace_XML/fichier_cri/schema.xsd

[ERROR] s4s-elt-invalid-content.1 : Le contenu de 'listeCri' n'est pas valide. L'élément 'element' n'est pas valide, est mal placé ou compte trop d'occurrences.
line 50 of file:***/Workspace_XML/fichier_cri/schema.xsd

[ERROR] s4s-elt-invalid-content.1 : Le contenu de 'fichierCri' n'est pas valide. L'élément 'element' n'est pas valide, est mal placé ou compte trop d'occurrences.
line 67 of file:***/Workspace_XML/fichier_cri/schema.xsd

Failed to parse a schema.

sorry for the french, but the error can be translated as something like this :

[ERROR] s4s-elt-invalid-content.1 : The content of 'heureType' is not valid. The element 'element' is not valid, is misplaced or appears to many times.

I tried to change the order of my code in multiple ways, but got nothing good.

Here is my code :

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema"> 

<!-- the Root Element -->
<xs:element name="fichier_cri" type="fichierCri"/> 


<!-- ########## LEVEL 0 ########## -->

    <xs:complexType name="fichierCri"> 
    <xs:element name="init_liaison" type="initLiaison" minOccurs="0" maxOccurs="unbounded"/> 
    <xs:sequence>
        <xs:element name="liste_cri" type="listeCri" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
</xs:complexType> 


<!-- ########## LEVEL 1 ########## -->  

<xs:complexType name="initLiaison"> 
    <xs:element name="source" type="xs:int" minOccurs="0" maxOccurs="unbounded"/> 
</xs:complexType> 

<xs:complexType name="listeCri"> 
    <xs:element name="demande_cri" type="demandeCri" minOccurs="0" maxOccurs="unbounded"/>
    <xs:element name="info_cri" type="infoCri" minOccurs="0" maxOccurs="unbounded"/>
    <xs:sequence>
        <xs:element name="cri" type="criType" minOccurs="0" maxOccurs="unbounded"/> 
    </xs:sequence>
</xs:complexType>


<!-- ########## LEVEL 2 ########## -->  

<xs:complexType name="demandeCri"> 
        <xs:element name="fichier_erreur" type="xs:string" minOccurs="0" maxOccurs="unbounded"/> 
</xs:complexType> 

<xs:complexType name="infoCri"> 
        <xs:element name="nb_erreur" type="xs:int" minOccurs="0" maxOccurs="unbounded"/> 
        <xs:element name="num_proch_erreur" type="xs:int" minOccurs="0" maxOccurs="unbounded"/> 
</xs:complexType> 

<xs:complexType name="criType"> 
        <xs:element name="num_erreur" type="xs:int" minOccurs="0" maxOccurs="unbounded"/> 
        <xs:element name="num_cri" type="xs:string" minOccurs="0" maxOccurs="unbounded"/> 
        <xs:element name="heure" type="heureType" minOccurs="0" maxOccurs="unbounded"/> 
        <xs:element name="data" type="dataType" minOccurs="0" maxOccurs="unbounded"/> 
</xs:complexType> 


<!-- ########## LEVEL 3 ########## -->  

<xs:complexType name="heureType"> 
        <xs:element name="secondes" type="xs:int" minOccurs="0" maxOccurs="unbounded"/> 
        <xs:element name="nano_secondes" type="xs:int" minOccurs="0" maxOccurs="unbounded"/> 
</xs:complexType> 

<xs:complexType name="dataType"> 
    <xs:sequence>
        <xs:element name="octet" type="xs:string" minOccurs="0" maxOccurs="unbounded"/> 
    </xs:sequence>
</xs:complexType> 


<!-- *** end *** -->    
</xs:schema> *

does someone know something about this ? :/


回答1:


The error message indicates that your xsd file is not syntactically correct. This is true. If you edit your xsd to fix the problems, the error messages should go away.

When you define a complex type:

<complexType name="foo">
    <sequence>
        <element ... />
        <element ... />
    </sequence>
</complexType>

Make sure that all elements within your complex types are within a sequence element. The <sequence> says that a valid document will contain the contained elements in the specified order.

Of course, there are other options available for defining your complex type. For example, you can use <choice> instead of <sequence>, which means that a valid document will contain one of the contained elements.

It is worthwhile to look at the schema (xsd) for schema files. Check out the link that you have in the top of your schema file (http://www.w3.org/2001/XMLSchema).



来源:https://stackoverflow.com/questions/38528099/jaxb-xjc-xml-schema-parsin-fail

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!