1
许多不同的属性,我想这样做: XML Schema How to Restrict Attribute by EnumerationXSD:限制取相同的值
...但我有采取完全相同的值的多个不同的属性。这使我的XSD非常复杂。 我可以定义限制一次,然后在每个属性上以某种方式引用它?
在此先感谢。 :)
许多不同的属性,我想这样做: XML Schema How to Restrict Attribute by EnumerationXSD:限制取相同的值
...但我有采取完全相同的值的多个不同的属性。这使我的XSD非常复杂。 我可以定义限制一次,然后在每个属性上以某种方式引用它?
在此先感谢。 :)
如果您有采取对完全相同的值许多不同的属性,简单地重用属性类型定义:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="1.0">
<xs:simpleType name="colorType">
<xs:restriction base="xs:string">
<xs:enumeration value="red" />
<xs:enumeration value="green" />
<xs:enumeration value="blue" />
</xs:restriction>
</xs:simpleType>
<xs:element name="RoomColors">
<xs:complexType>
<xs:attribute name="wall" type="colorType"/>
<xs:attribute name="carpet" type="colorType"/>
<xs:attribute name="ceiling" type="colorType"/>
<xs:attribute name="funiture" type="colorType"/>
</xs:complexType>
</xs:element>
</xs:schema>
这是当值不完全相同的是有涉及更多的创造力。见Extend enumerated lists in XML schema。
酷!有用!非常感谢! :) – user2173353