1

我们收到了一个 XSD 文档,该文档将两个应用程序之间的数据传输格式指定为 XML 文档。映射并不像我希望的那样,我想使用自定义.xjb映射文件对其进行自定义。

xsd如下

<xsd:complexType name="selection">
    <xsd:choice minOccurs="1" maxOccurs="unbounded">
        <xsd:element name="area" type="area"/>
        <xsd:element name="range" type="range"/>
        <xsd:element name="exact" type="exact"/>
    </xsd:choice>
</xsd:complexType>
<xsd:simpleType name="area">
    <xsd:restriction base="xsd:string">
        <xsd:pattern value="[0-9]{2}"/>
    </xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="range">
    <xsd:restriction base="xsd:string">
        <xsd:pattern value="[0-9]{2}-[0-9]{2}"/>
    </xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="exact">
    <xsd:restriction base="xsd:string">
        <xsd:pattern value="[0-9]{5}"/>
    </xsd:restriction>
</xsd:simpleType>

默认情况下,这会生成以下Selection

public class Selection {

    @XmlElementRefs({
        @XmlElementRef(name = "exact", type = JAXBElement.class),
        @XmlElementRef(name = "range", type = JAXBElement.class),
        @XmlElementRef(name = "area", type = JAXBElement.class)
    })
    protected List<JAXBElement<String>> areaOrRangeOrExact;
    ...
}

最好,我希望它产生类似的东西

public class Selection {
    protected List<Exact> exacts;
    protected List<Area> areas;
    protected List<Range> ranges;
    ...
}

或者,如果他们扩展了一个超类,比如说SelectionType

public class Selection {

    @XmlElementRefs({
        @XmlElementRef(name = "exact", type = Exact.class),
        @XmlElementRef(name = "range", type = Range.class),
        @XmlElementRef(name = "area", type = Area.class)
    })
    protected List<SelectionType> selection;
    ...
}

我可以在不修改原始 XSD 的情况下实现这一点吗?

4

0 回答 0