如何在XSD中为多个元素重用复杂类型?
问题描述:
我一直无法找到任何有关这方面的信息,可能是由于我没有使用术语。我想要做的是为货币创建一个模板元素,我已经拥有这个模板元素,并在两个不同的名称下使用它(即currentBalance
和maxBalance
)。如何在XSD中为多个元素重用复杂类型?
我目前这个模板的格式是:
<xsd:element name="currency">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="xsd:double">
<xsd:attribute ref="currencyCode" />
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
答
简单的全局定义和命名复杂类型要使用,
<xsd:complexType name="currency">
<xsd:simpleContent>
<xsd:extension base="xsd:double">
<xsd:attribute ref="currencyCode" />
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
然后引用需要的地方:
<xsd:element name="currentBalance" type="currency"/>
<xsd:element name="maxBalance" type="currency"/>