可重用的complexType和xml-registry,xml-element-decl用法 [英] Reusable complexType, and xml-registry, xml-element-decl usage

查看:95
本文介绍了可重用的complexType和xml-registry,xml-element-decl用法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在下面 TimePeriodType

<xs:simpleType name="UnitOfTimePeriodType">
    <xs:restriction base="xs:token">
        <xs:enumeration value="Months"/>
        <xs:enumeration value="Days"/>
        <xs:enumeration value="Years"/>
    </xs:restriction>
</xs:simpleType>
<xs:complexType name="TimePeriodType">
    <xs:sequence>
        <xs:element name="Length" type="digit1-3"/>
    </xs:sequence>
    <xs:attribute name="unitOfLength" type="UnitOfTimePeriodType" use="optional" default="Months"/>
</xs:complexType>

可以使用多种类型,如下所示

which gets used in multiple types as shown below

<xs:complexType name="USAddressType">
    <xs:complexContent>
        <xs:extension base="AddressType">
            <xs:sequence>                   
                <xs:element name="LengthAtAddress" type="TimePeriodType" minOccurs="0"/>
            </xs:sequence>
        </xs:extension>
    </xs:complexContent>
</xs:complexType>

<xs:complexType name="CanadaAddressType">
    <xs:complexContent>
        <xs:extension base="AddressType">
            <xs:sequence>
                <xs:element name="LengthAtAddress" type="TimePeriodType" minOccurs="0"/>
            </xs:sequence>
        </xs:extension>
    </xs:complexContent>
</xs:complexType>

因此,以下实例xml

So, the below instance xml

<LengthAtAddress unitOfLength="Months">
    <Length>36</Length>
</LengthAtAddress>

应映射到以下pojo

should be mapped to the following pojo

public abstract class AbstractAddress
{
    protected int lengthAtAddress;
    protected UnitOfLengthType unitOfLengthAtAddress;

    public int getLengthAtAddress()
    {
        return lengthAtAddress;
    }

    public UnitOfLengthType getUnitOfLengthAtAddress()
    {
        return unitOfLengthAtAddress;
    }

    //setters
}

我认为在使用外部映射时,我应该使用 xml-registry xml-element-decl 的组合。无法弄清楚我们如何。任何帮助表示赞赏。

I think I should be using a combination of xml-registry and xml-element-decl while using external mapping. Not able to figure our how. Any help is appreciated.

FIX

<xml-element java-attribute="lengthAtAddress" xml-path="LengthAtAddress/Length/text()"/>
    <xml-element java-attribute="unitOfLengthAtAddress" xml-path="LengthAtAddress/@unitOfLength">
    <xml-java-type-adapter value="com.equifax.ic.platform.sts.domain.transformation.response.CommonsEnumAdapter"/>
</xml-element>


推荐答案

你可以使用MOXy的 @ XmlPath 扩展名或MOXy外部映射文档中的等效文件。

You could use MOXy's @XmlPath extension or the equivalent in MOXy's external mapping document.

@XmlPath("LengthAtAddress/Length/text()")
public int getLengthAtAddress()
{
    return lengthAtAddress;
}

这篇关于可重用的complexType和xml-registry,xml-element-decl用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆