我想将 Name
属性的类型从 xs:string
更改为 xs:int
,如下面的 XSD 中
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.my.own/2013/XMLSchema">
<xs:complexType name="AType">
<xs:attribute name="Name" type="xs:string" use="required" />
</xs:complexType>
<xs:complexType name="BType">
<xs:complexContent>
<xs:extension base="AType">
<xs:sequence>
<xs:choice>
<xs:element name="Content" type="xs:string"/>
</xs:choice>
</xs:sequence>
<xs:attribute name="Name" type="xs:int" use="required"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
此 XSD 有效吗?如果没有,是否存在其他解决方案来更改属性类型?
最佳答案
不,类型派生的原则是,如果从基类型派生出新类型,则派生类型的实例仍然必须是基类型的有效实例。因此您无法将属性从字符串更改为整数。
关于xml - XSD - 可以更改扩展类型中的属性类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15086703/