注意:我是
EclipseLink JAXB (MOXy)領導者,也是
JAXB 2 (JSR-222)專家組的成員.
Can Castor do this? If so, what would be the Ant task syntax for it.
If not, would perhaps JAXB be a better alternative?
下面是如何使用JAXB完成此操作的示例:
產品
xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/Product"
xmlns:tns="http://www.example.org/Product"
elementFormDefault="qualified">
由于多個XML模式導入Product.xsd,因此我們可以利用episode文件,以便只生成一次與Product.xsd相對應的類.
xjc -d out -episode product.episode Product.xsd
ProductPurchaseRequest.xsd
下面是導入Product.xsd的XML模式的示例:
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">
當我們從這個XML模式生成類時,我們將引用我們從Product.xsd生成Java類時創建的劇集文件.
xjc -d out ProductPurchaseRequest.xsd -extension -b product.episode
ProductQuoteRequest.xsd
下面是導入Product.xsd的XML模式的另一個示例:
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">
再次,當我們從這個XML模式生成類時,我們將引用我們從Product.xsd生成Java類時創建的劇集文件.
xjc -d out ProductQuoteRequest.xsd -extension -b product.episode
了解更多信息