注:私はEclipseLink JAXB (MOXy)のリーダーであり、JAXB 2 (JSR-222)エキスパート グループのメンバーです。
キャスターはこれを行うことができますか? もしそうなら、Ant タスクの構文はどうなるでしょうか。そうでない場合、おそらく JAXB がより良い代替手段になるでしょうか?
以下は、JAXB を使用してこれを行う方法の例です。
製品
<?xml version="1.0" encoding="UTF-8"?>
<schema
xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/Product"
xmlns:tns="http://www.example.org/Product"
elementFormDefault="qualified">
<element name="product">
<complexType>
<sequence>
<element name="id" type="string"/>
<element name="name" type="string"/>
</sequence>
</complexType>
</element>
</schema>
複数の XML スキーマが Product.xsd をインポートするため、エピソード ファイルを利用して、Product.xsd に対応するクラスが 1 回だけ生成されるようにすることができます。
xjc -d out -episode product.episode Product.xsd
ProductPurchaseRequest.xsd
以下は、Product.xsd をインポートする XML スキーマの例です。
<?xml version="1.0" encoding="UTF-8"?>
<schema
xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/ProductPurchaseRequest"
xmlns:tns="http://www.example.org/ProductPurchaseRequest"
xmlns:prod="http://www.example.org/Product"
elementFormDefault="qualified">
<import namespace="http://www.example.org/Product" schemaLocation="Product.xsd"/>
<element name="purchase-request">
<complexType>
<sequence>
<element ref="prod:product" maxOccurs="unbounded"/>
</sequence>
</complexType>
</element>
</schema>
この XML スキーマからクラスを生成するとき、Product.xsd から Java クラスを生成したときに作成したエピソード ファイルを参照します。
xjc -d out ProductPurchaseRequest.xsd -extension -b product.episode
ProductQuoteRequest.xsd
以下は、Product.xsd をインポートする XML スキーマの別の例です。
<?xml version="1.0" encoding="UTF-8"?>
<schema
xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/ProductQuoteRequest"
xmlns:tns="http://www.example.org/ProductQuoteRequest"
xmlns:prod="http://www.example.org/Product"
elementFormDefault="qualified">
<import namespace="http://www.example.org/Product" schemaLocation="Product.xsd"/>
<element name="quote">
<complexType>
<sequence>
<element ref="prod:product"/>
</sequence>
</complexType>
</element>
</schema>
この XML スキーマからクラスを生成するときも、Product.xsd から Java クラスを生成したときに作成したエピソード ファイルを参照します。
xjc -d out ProductQuoteRequest.xsd -extension -b product.episode
詳細については