2012-11-29 3 views
3

J'utilise JAXB avec les éléments suivants sur mesure contraignante:JAXB - Redéfinition d'un type de données élément

<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" version="2.0" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" jaxb:extensionBindingPrefixes="xjc" xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    <jaxb:globalBindings typesafeEnumMaxMembers="2000"> 
     <jaxb:serializable /> 
    </jaxb:globalBindings> 
     <jaxb:bindings schemaLocation="test.xsd" node="/xs:schema//xs:complexType[@name='EN']//xs:element[@name='family']"> 
      <jaxb:property> 
       <jaxb:baseType name="java.lang.String" /> 
      </jaxb:property> 
     </jaxb:bindings> 
</jaxb:bindings> 

pour gérer ce schéma (test.xsd):

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> 
    <xsd:complexType name="EN" mixed="true"> 
     <xsd:complexContent> 
     <xsd:extension base="ANY"> 
      <xsd:sequence> 
       <xsd:choice minOccurs="0" maxOccurs="unbounded"> 
        <xsd:element name="family" type="en.family"/> 
       </xsd:choice> 
      </xsd:sequence> 
     </xsd:extension> 
     </xsd:complexContent> 
    </xsd:complexType> 
    <xsd:complexType name="en.family" mixed="true"> 
     <xsd:complexContent> 
     <xsd:restriction base="ENXP"> 
     </xsd:restriction> 
     </xsd:complexContent> 
    </xsd:complexType> 
    <xsd:complexType name="ENXP" mixed="true"> 
     <xsd:complexContent> 
     <xsd:extension base="ST"> 
     </xsd:extension> 
     </xsd:complexContent> 
    </xsd:complexType> 
    <xsd:complexType name="ST" mixed="true"> 
     <xsd:complexContent> 
     <xsd:restriction base="ED"> 
     </xsd:restriction> 
     </xsd:complexContent> 
    </xsd:complexType> 
    <xsd:complexType name="ED" mixed="true"> 
     <xsd:complexContent> 
     <xsd:extension base="BIN"> 
     </xsd:extension> 
     </xsd:complexContent> 
    </xsd:complexType> 
    <xsd:complexType name="BIN" abstract="true" mixed="true"> 
     <xsd:complexContent> 
     <xsd:extension base="ANY"> 
     </xsd:extension> 
     </xsd:complexContent> 
    </xsd:complexType> 
    <xsd:complexType name="ANY" abstract="true"> 
     <xsd:attribute name="nullFlavor" type="xsd:string" use="optional"> 
     </xsd:attribute> 
    </xsd:complexType> 
</xsd:schema> 

Et je rencontre ce problème:

[ERROR] compiler was unable to honor this property customization. It is attached to a wrong place, or its inconsistent with other bindings. 
    line 6 of file://home/user/test/jaxbelem_binding.xml 

[ERROR] (the above customization is attached to the following location in the schema) 
    line 7 of file://home/user/test/test.xsd 

Failed to parse a schema. 

Quel est le problème avec mon fichier de liaison? Il est à propos de jaxb:property, mais lorsque ce dernier est supprimé, aucun dépassement ne se produit!

Toute aide sera vraiment appréciée, merci d'avance les gens!

+0

Je tryied cela aussi: \t Mais je reçois la même erreur" le compilateur n'a pas pu honorer cette personnalisation javaType " – Ben

Répondre

2

J'ai eu la chance de nidification la balise jxb:bindings node à l'intérieur de la balise jxb:bindings schemaLocation comme ceci:

<?xml version="1.0" encoding="US-ASCII" ?> 
<jxb:bindings version="2.0" 
    xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" 
    xmlns:jxb="http://java.sun.com/xml/ns/jaxb" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd" 
> 

    <jxb:bindings schemaLocation="test.xsd"> 
     <jxb:bindings node="//xs:element[@name='family']"> 
      <jxb:property > 
       <jxb:baseType name="java.lang.String"></jxb:baseType> 
      </jxb:property> 
     </jxb:bindings> 
    </jxb:bindings> 
</jxb:bindings> 

aussi:

  • alors que votre note XPath à la 'famille' fonctionne, il semble trop compliqué. Je mis à jour à un qui fonctionne donné votre exemple xsd (tant qu'il n'y a qu'un seul élément avec le nom = « famille », il travaillera)
Questions connexes