2

假设我有以下 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所有产品交叉引用回原始国家/类型。

所以,我的问题是:

是否可以将此模式编译成可以使用 Eclipse Moxy 解组的 Java 类,并且交叉引用完好无损?

我知道 JAXB 2.0 规范不支持 key/keyref。我也知道Moxy可以。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 而不是CountryandType对象。

4

1 回答 1

1

目前EclipseLink JAXB (MOXy)仅扩展 XJC 工具以添加一个jaxb.properties文件,该文件指示 MOXy 是JAXB (JSR-222)提供程序。我已输入以下增强功能(当前未计划)来跟踪此请求:

于 2013-06-25T15:43:50.637 回答