我的 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>
使用多种类型,如下所示
<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
<LengthAtAddress unitOfLength="Months">
<Length>36</Length>
</LengthAtAddress>
应映射到以下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 的组合。无法弄清楚我们如何。任何帮助表示赞赏。
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>
答案 0 :(得分:1)
你可以在MOXy的外部地图文档中使用MOXy的@XmlPath
扩展名或等效名称。
@XmlPath("LengthAtAddress/Length/text()")
public int getLengthAtAddress()
{
return lengthAtAddress;
}