私は Eclipse で Dali プラグインを使用して、xsd ファイルを使用して Java クラスを生成します。これは基本的に、スキーマ ファイルで xjc を呼び出すだけです。ここでのアドバイスを使用して、XML バインディング ファイルをクラス生成に適用することで名前の競合を解決しました。これはうまくいきましたが、ルート要素の名前を変更してさらに一歩進めようとした結果、XmlRootElement 注釈が失われました。annox を使用してルート要素の注釈を追加しようとしましたが、次のエラーが表示されます: Unsupported binding namespace " http://annox.dev.java.net ". おそらく、「 http://java.sun.com/xml/ns/jaxb/xjc 」という意味ですか?
これが私の最初のbinding.xmlファイルです(annoxなし):
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" 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"
version="2.1">
<!-- Force all classes to be generated at the top level, this will potentially cause name conflicts -->
<jaxb:globalBindings localScoping="toplevel"/>
<jaxb:bindings schemaLocation="mySchema-1.0.0.xsd">
<!-- Rename the root element -->
<jaxb:bindings node="//xs:element[@name='MyRootClassNameIsReallyLong']/xs:complexType">
<jaxb:class name="ShorterName"/>
</jaxb:bindings>
<!-- Rename the Bar class to resolve a naming conflict -->
<jaxb:bindings node="//xs:element[@name='Foo']/xs:complexType/xs:sequence/xs:element[@name='Bar']/xs:complexType">
<jaxb:class name="FooBar"/>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
ちなみに、スキーマ ファイルはサード パーティから入手したものなので、変更するつもりはありません。同様に、生成された Java ファイルを改ざんしたくないので、バインド xml アプローチに関心があります。
編集 (2013 年 9 月 11 日) - annox を使用したバインディング XML は次のとおりです。
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" 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"
xmlns:annox="http://annox.dev.java.net"
version="2.1">
<!-- Force all classes to be generated at the top level, this will potentially cause name conflicts -->
<jaxb:globalBindings localScoping="toplevel"/>
<jaxb:bindings schemaLocation="mySchema-1.0.0.xsd">
<!-- Rename the root element -->
<jaxb:bindings node="//xs:element[@name='MyRootClassNameIsReallyLong']/xs:complexType">
<jaxb:class name="ShorterName"/>
<annox:annotate>
<annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="MyRootClassNameIsReallyLong" />
</annox:annotate>
</jaxb:bindings>
<!-- Rename the Bar class to resolve a naming conflict -->
<jaxb:bindings node="//xs:element[@name='Foo']/xs:complexType/xs:sequence/xs:element[@name='Bar']/xs:complexType">
<jaxb:class name="FooBar"/>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>