【发布时间】:2014-07-31 13:07:31
【问题描述】:
我需要使用相同的两个属性 att1 和 att2 一遍又一遍地扩展不同 XML Schema 内置类型(例如 xs:anyURI、xs:string...)的几个 xml 元素。
要验证的示例 xml:
<extendedURI att1="abc" att2="def">my.uri</extendedURI>
我已经尝试定义一个复杂类型的父类:
<!-- The parent type defines the two attributes I'm interested in -->
<xs:complexType name="parentType">
<xs:attribute name="att1" type="xs:string" />
<xs:attribute name="att2" type="xs:string" />
</xs:complexType>
然后将我的元素的类型声明为xs:anyURI 并扩展它们,但这无效:
<!-- XXX: The following is not permitted: I cannot redefine the xs:anyURI type -->
<xs:element name="extendedURI" type="xs:anyURI">
<xs:complexType>
<xs:complexContent>
<xs:extension base="parentType" />
</xs:complexContent>
</xs:complexType>
</xs:element>
我还尝试将 simpleContent 限制为 xs:anyURI 并使用 parentType 扩展它,但我找不到如何操作。比如:
<xs:element name="extendedURI">
<xs:complexType>
<xs:simpleContent>
<!-- XXX: This is not permited: -->
<xs:restriction base="xs:anyURI">
</xs:restriction>
<xs:extension base="parentType">
</xs:extension>
<!-- 'xs:restriction' and 'xs:extension' are alternatives and
cannot be defined at the same time!
-->
<xs:simpleContent>
</xs:complexType>
</xs:element>
那么我怎么能做到这一点呢?是否可以使用 complexType 扩展内置类型(或使用内置类型的定义来限制 complexType)?
【问题讨论】:
标签: xsd