2013-03-15 53 views
1

在XML模式,如何讓元素Agerestriction以允許寫入整數與10最大值和最小值1,內部元件Age也元素Age有屬性?沒有警告XML架構的制約性屬性

<Age type="sth"> 
5 
</Age> 

XML代碼與預警

<Age type="sth"> 
22 
</Age> 

回答

3

<xsd:element name="Age"> 
    <xsd:complexType> 
here i want to have restriction to control max and min value inside Age element 
    <xsd:attribute name="type" type="xsd:string" use="required" /> 
    </xsd:complexType> 
</xsd:element> 

XML代碼被稱爲 「複雜類型具有簡單內容」。舉個例子:

<xs:complexType> 
    <xs:simpleContent> 
    <xs:extension base="one-to-ten"> 
     <xs:attribute name="type" type="xs:string" use="required"/> 
    </ 
    </ 
</ 

<xs:simpleType name="one-to-ten"> 
    <xs:restriction base="xs:integer"> 
    <xs:minInclusive value="1"/> 
    <xs:maxInclusive value="10"/> 
    </ 
</