1

複数の XSD ファイルがあり、それらに対して XJC を実行して、さらなる処理に使用する Java クラス オブジェクトを作成したいと考えています。 問題: XJC コマンドを実行すると、XSD セットの 2 つの XSD に問題があります。XSD は次のとおりです。

contactLM.xsd

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
            xmlns:w="http://w.com/xsd" 
            xmlns="http://w.com/location.contactlm" 
            xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" 
            targetNamespace="http://w.com/location.contactlm" 
            elementFormDefault="qualified" jaxb:version="2.1">
  <xsd:annotation>
    <xsd:appinfo>
      <jaxb:schemaBindings>
        <jaxb:package name="location.contactlm"/> 
      </jaxb:schemaBindings>
    </xsd:appinfo>
  </xsd:annotation>

  <xsd:element name="Contact" type="Contact" nillable="true"/>

  <xsd:complexType name="Contact">
    <xsd:sequence>
      <xsd:element name="RefID" type="xsd:string" nillable="true" 
                   minOccurs="0" gw:type="java.lang.String"/>
    </xsd:sequence>
  </xsd:complexType>


</xsd:schema>

contactM.xsd

<?xml version="1.0"?>
<xsd:schema
      xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      xmlns:w="http://w.com/xsd"
      xmlns="http://w.com/location.contactm"
      targetNamespace="http://w.com/location.contactm"
      elementFormDefault="qualified"
      xmlns:ns0="http://w.com/location.contactam"
      xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"  
      jaxb:version="2.1">
  <xsd:annotation>
    <xsd:appinfo>
      <jaxb:schemaBindings>
        <jaxb:package name="location.contactm"/>
      </jaxb:schemaBindings>
    </xsd:appinfo>
  </xsd:annotation>
  <xsd:import namespace="http://w.com/location.contactam"
              schemaLocation="ContactAM.xsd"/>
  <xsd:element name="Contact" type="Contact" nillable="true"/>
  <xsd:complexType name="Contact">
    <xsd:sequence>
      <xsd:element name="RefID" minOccurs="0" nillable="true" 
                   type="xsd:string" gw:type="java.lang.String"/>
      <xsd:element name="WorkPhone" minOccurs="0" nillable="true" 
                   type="xsd:string" gw:type="java.lang.String"/>
    </xsd:sequence>
  </xsd:complexType>
</xsd:schema>

これらの XSD ファイルに同じ「連絡先」への参照があることは知っていますが、それが問題です。そう、私は XJB ファイルを書かなければなりませんでした。次の xjb ファイルを作成しました。

<jaxb:bindings
  xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
  xmlns:gw="http://w.com/xsd" 
  xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" 
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  elementFormDefault="qualified" 
  xmlns="http://w.com/location.contactlm" 

  targetNamespace="http://w.com/location.contactlm" 
  jaxb:version="2.1">

     <jaxb:bindings schemaLocation="ContactM.xsd">
        <jaxb:bindings node=".//xs:element[@name='Contact']">
            <jaxb:class name="ContactM"/>
        </jaxb:bindings>
        <jaxb:schemaBindings>
            <jaxb:package name="location.contactm" />
        </jaxb:schemaBindings>
    </jaxb:bindings>

   <jaxb:bindings schemaLocation="ContactLM.xsd">
        <jaxb:bindings node=".//xs:element[@name='Contact']">
            <jaxb:class name="ContactCLM"/>
        </jaxb:bindings>
        <jaxb:schemaBindings>
            <jaxb:package name="location.contactlm" />
        </jaxb:schemaBindings>
    </jaxb:bindings>

</jaxb:bindings>

しかし、次のエラーが表示されます。

xjc -d src -b C:\us\binding.xjb C:\us\trunk\shared\


parsing a schema...
346368376 / 346685920 (-1 / -1) (com/sun/tools/internal/xjc/reader/xmlschema/bindinfo/CollectionTypeAttribute$JaxbAccessorF_collectionType/com/sun/tools/internal/xjc/reader/xmlschema/bindinfo/CollectionTyp
eAttribute$JaxbAccessorF_collectionType)
[ERROR] Multiple <schemaBindings> are defined for the target namespace "http://w.com/location.contactm"
  line 10 of file:/C:/us/trunk/contact/ContactM.xsd

[ERROR] Another <schemaBindings> is defined here
  line 14 of file:/C:/us/trunk/contact/binding.xjb

[ERROR] Multiple <schemaBindings> are defined for the target namespace "http://w.com//trunk/contactlm"
  line 5 of file:/C:/us/trunk/contact/ContactLM.xsd

[ERROR] Another <schemaBindings> is defined here
  line 23 of file:/C:/us/trunk/contact/binding.xjb

[ERROR] compiler was unable to honor this schemaBinding customization. It is attached to a wrong place, or its inconsistent with other bindings.
  line 14 of file:/C:/us/trunk/contact/binding.xjb

[ERROR] (the above customization is attached to the following location in the schema)
  line 10 of file:/C:/us/trunk/contact/ContactM.xsd

[ERROR] compiler was unable to honor this schemaBinding customization. It is attached to a wrong place, or its inconsistent with other bindings.
  line 23 of file:/C:/us/trunk/contact/binding.xjb

[ERROR] (the above customization is attached to the following location in the schema)
  line 2 of file:/C:/us/trunk/contact/ContactLM.xsd

Failed to parse a schema.

XJB ファイルで何か間違ったことをしている可能性があると思いますが、問題を修正できません。誰か助けてください。

4

1 に答える 1