2013-09-25 32 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