注意: 我是 Eclipselink
JAXB(MOXy)的 负责人,并且是 JAXB
2(JSR-222) 专家组的成员。
.episode文件由XJC(XML Schema to
Java)编译器生成。它是将架构类型与现有类相关联的架构绑定。当您拥有一个由其他模式导入的XML模式时,此方法很有用,因为它会阻止重新生成模型。下面是一个示例:
产品.xsd
<?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对应的类仅生成一次。
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
想要查询更多的信息
- http://blog.bdoughan.com/2011/12/reusing-generation-jaxb-classes.html



