【发布时间】:2013-06-22 10:54:12
【问题描述】:
假设我有以下 XML 架构:
<xs:schema
xmlns="http://www.example.com/data"
xmlns:data="http://www.example.com/data"
targetNamespace="http://www.example.com/data"
elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="data">
<xs:complexType>
<xs:all>
<xs:element name="countries">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="country" type="country"/>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="types">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="type" type="type"/>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="products">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="product" type="product"/>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:all>
</xs:complexType>
<xs:key name="countryNameKey">
<xs:selector xpath=".//data:country"/>
<xs:field xpath="@name"/>
</xs:key>
<xs:key name="typeNameKey">
<xs:selector xpath=".//data:type"/>
<xs:field xpath="@name"/>
</xs:key>
<xs:keyref name="countryNameRef" refer="data:countryNameKey">
<xs:selector xpath=".//data:product"/>
<xs:field xpath="@country"/>
</xs:keyref>
<xs:keyref name="typeNameRef" refer="data:typeNameKey">
<xs:selector xpath=".//data:product"/>
<xs:field xpath="@type"/>
</xs:keyref>
<xs:unique name="uniqueProducts">
<xs:selector xpath=".//data:product"/>
<xs:field xpath="@country"/>
<xs:field xpath="@type"/>
</xs:unique>
</xs:element>
<xs:complexType name="country">
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:complexType>
<xs:complexType name="type">
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:complexType>
<xs:complexType name="product">
<xs:attribute name="country" type="xs:string" use="required"/>
<xs:attribute name="type" type="xs:string" use="required"/>
</xs:complexType>
</xs:schema>
请原谅这个人为的例子。
如您所见,它是表格数据。我定义了一些国家,然后我定义了一些产品类型。然后,我将单个产品定义为来自某个国家/地区的类型,例如来自法国的奶酪。
这里要注意的重要一点是,我使用key 和keyref 将所有产品交叉引用回原始国家/地区/类型。
所以,我的问题是:
是否可以将此模式编译成 java 类,以便使用 Eclipse Moxy 解组,并保持交叉引用不变?
我知道 JAXB 2.0 规范确实有 not support key/keyref。我也知道Moxy Does.1
此外,我知道 Moxy 没有 Maven 插件,无论如何,它使用 XJC 生成的类,并简单地添加一个 jaxb.properties 文件来指定要使用的 JAXB 提供程序。2支持>
所以我怀疑我的问题的答案是“不,你必须自己制作课程”,但我想在放弃希望之前先检查一下。
澄清一下,我的product 元素当前编译(使用maven-jaxb2-plugin)到
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "product")
public class Product implements Cloneable, CopyTo, Equals, HashCode, ToString {
@XmlAttribute(name = "country", required = true)
protected String country;
@XmlAttribute(name = "type", required = true)
protected String type;
//getters and setters
}
它引用 Strings 而不是 Country 和 Type 对象。
【问题讨论】:
-
反对者请发表评论。