1

我正在从第 3 方提供的 xsd 文件(准确地说是 ONIX XML 文件 XSD)生成 Java 类。模式定义了相当多的类型,它们具有 ashortname和 arefname属性。不幸的是,ONIX 人员没有使用该fixed属性为这些字段设置单个允许的字符串值,而是这样做:

<xs:attribute name="refname">
    <xs:simpleType>
        <xs:restriction base="xs:token">
            <xs:enumeration value="AddresseeIDType"/>
        </xs:restriction>
    </xs:simpleType>
</xs:attribute>

<xs:attribute name="shortname">
    <xs:simpleType>
        <xs:restriction base="xs:token">
            <xs:enumeration value="m380"/>
        </xs:restriction>
    </xs:simpleType>
</xs:attribute>

这会导致 JAXB 为 shortname 和 refname 属性生成可变字符串字段。在类生成过程中,有关这些字段的唯一有效值的信息会丢失。

有没有办法使用外部 JAXB 绑定文件让 XJC 为以下形式生成shortname字段refname

@XmlAttribute(name = "refname")
protected static final String refname = "AddresseeIDType";

@XmlAttribute(name = "shortname")
protected static final String shortname = "m380";

我知道有一个fixedAttributeAsConstantProperty属性,但这似乎只起作用,如果 xsd 改为以以下方式定义shortnameand :refname

<xs:attribute name="refname" fixed="AddresseeIDType" />
<xs:attribute name="shortname" fixed="m380" />

任何帮助表示赞赏

4

0 回答 0