我一直在做很多研究试图弄清楚这一点,但仍然没有成功。
我有许多遵循此架构的 XSD:
Simple_Identification.xsd
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:include schemaLocation="./Base_3039.xsd"/>
<xsd:include schemaLocation="./Simple_A.xsd"/>
<xsd:include schemaLocation="./Simple_S.xsd"/>
<xsd:include schemaLocation="./Simple_N.xsd"/>
<xsd:include schemaLocation="./Simple_V1.xsd"/>
<xsd:include schemaLocation="./Simple_L.xsd"/>
<xsd:include schemaLocation="./Simple_V.xsd"/>
<xsd:include schemaLocation="./Simple_C.xsd"/>
<xsd:simpleType name="Simple_Identification">
<xsd:restriction base="Base_3039"/>
</xsd:simpleType>
</xsd:schema>
例如Simple_S.xsd如下所示:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:include schemaLocation="./Simple_Identification.xsd"/>
<xsd:simpleType name="Simple_S">
<xsd:restriction base="Simple_Identification">
<xsd:minLength value="14"/>
<xsd:maxLength value="14"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
最终,我希望能够生成包含如下标签的 XML 文件:
<Identification xsi:type="Simple_S">XYZUVW</Identification>
现在,在不启用 mapSimpleTypeDef 的情况下,我能够编组/解组 XML 文件,而忽略 Simple_S 等简单类型。
启用 mapSimpleTypeDef 后,将为简单类型生成类。Simple_Identification 映射到包含 Base_3039 字段的类。Base_3039 类包含一个字符串字段。但是,Simple_Identifications 的不同子类型的类不扩展 Simple_Identification,而仅包含 Simple_Identification 类型的字段,这在编组/解组时没有帮助。
例如,在解组此 XML 文件时:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Header xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="...">
<Identification>EDS-200708021031-950012222329</Identification>
<Time>2007-08-02T10:31:44.449+01:00</Time>
<Function>9</Function>
<Sender>
<Identity xsi:type="Simple_S">111111380002111</Identity>
</Sender>
</Header>
Identity 的值被解组为 Simple_Identification 对象,而不是专门的 Simple_S 对象。此外,如果我重新编组所有 xsi:type 属性在生成的 XML 中丢失。
所以,基本上,我的问题是如何正确解组并生成包含 xsi:types 的 XML。我正在使用的模式是否不适合这样做?xsd:restriction 不被 JAXB 解释为一种继承吗?
请注意,XSD 不是我要修改的,我只需要使用它们来正确读取和生成 XML。
感谢您花时间帮我解决这个问题!
-安卡