Attribute
這邊用很快的速度介紹屬性(Attribute),屬性的宣告和simple element 是一樣的,所以其他廢話就不多說了。值得注意的是,在XML裡,物件的屬性都是非必要的,如果是必要屬性,則須加上use="required"。
例如以下語法,就代表lang 這個屬性是必要的:
<xs:attribute name="lang" type="xs:string" use="required"/> |
接下來是有點無聊的限制(Restrictions),可以告訴XML 某個數值的限制,例如得分最大不能超過100,最小不能小於0。
<score>98</score> |
就可以用以下Schema 限制:
<xs:element name="score"> <xs:simpleType> <xs:restriction base="xs:integer"> <xs:minInclusive value="0"/> <xs:maxInclusive value="100"/> </xs:restriction> </xs:simpleType> </xs:element> |
好…費話不多說(因為再多說對速成也許沒幫助),這邊列出原文中可以用在限制的內容:
Constraint | Description |
enumeration | Defines a list of acceptable values |
fractionDigits | Specifies the maximum number of decimal places allowed. Must be equal to or greater than zero |
length | Specifies the exact number of characters or list items allowed. Must be equal to or greater than zero |
maxExclusive | Specifies the upper bounds for numeric values (the value must be less than this value) |
maxInclusive | Specifies the upper bounds for numeric values (the value must be less than or equal to this value) |
maxLength | Specifies the maximum number of characters or list items allowed. Must be equal to or greater than zero |
minExclusive | Specifies the lower bounds for numeric values (the value must be greater than this value) |
minInclusive | Specifies the lower bounds for numeric values (the value must be greater than or equal to this value) |
minLength | Specifies the minimum number of characters or list items allowed. Must be equal to or greater than zero |
pattern | Defines the exact sequence of characters that are acceptable |
totalDigits | Specifies the exact number of digits allowed. Must be greater than zero |
whiteSpace | Specifies how white space (line feeds, tabs, spaces, and carriage returns) is handled |
英文也很好懂…我就不逐字翻譯了。
下一篇:XML Schema 從看不懂到慢慢懂 - part 4
讀者回應 ( 0 意見 )
訂閱張貼留言 (Atom)
張貼留言
如果沒有帳戶,建議使用「名稱/網址」留言喔^^