2013-09-25 26 views

回答

2

如果您有采取对完全相同的值许多不同的属性,简单地重用属性类型定义:

<?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

+0

酷!有用!非常感谢! :) – user2173353