在XML模式中,所有全局元素、属性或类型定义都必须限定。因此,即使您将attributeFormDefault定义为“unqualified”,所有全局定义的属性都将以名称空间为前缀。解决方法是在属性组或全局类型中定义此属性,然后可以引用此命名组或扩展此命名类型。
<xs:attributeGroup name="unaryGroup">
<xs:attribute name="unaryOperator">
<xs:annotation>
<xs:documentation>Negate an entire expression.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="not"></xs:enumeration>
<xs:enumeration value="-"></xs:enumeration>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:attributeGroup>
当需要此属性时,请参考attributeGroup而不是属性。属性组不需要包含元素使用的所有属性,这也应该是有效的:
<xs:complexType name="UnaryType">
<xs:attributeGroup ref="unaryGroup"/>
<xs:attribute name="otherAttribute" type="xs:string"/>
</xs:complexType>