XML Tutorial/XML Schema/list
Версия от 18:22, 25 мая 2010; (обсуждение)
Содержание
- 1 A list data type is derived from an atomic data type that allows white space
- 2 length of our list is five
- 3 Restrict a list type with the xsd:length, xsd:maxLength, xsd:minLength, and xsd:enumeration facets.
- 4 The list method uses a finite sequence of itemType attributes to derive a new type
- 5 Using a <list> declaration, you can base your list items on a specific <simpleType>
A list data type is derived from an atomic data type that allows white space
<!-- schema -->
<simpleType name="myLuckyNumbers">
<list itemType="decimal"/>
</simpleType>
<!-- instance document -->
<numbers xsi:type="myLuckyNumbers"> 3 7 13 17 21.5 </numbers>
length of our list is five
<!-- schema -->
<simpleType name="myString">
<list itemType="string"/>
</simpleType>
<!-- instance document -->
<string_list xsi:type="myString">
This string is a list
</string_list>
Restrict a list type with the xsd:length, xsd:maxLength, xsd:minLength, and xsd:enumeration facets.
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.wbex.ru"
xmlns="http://www.wbex.ru"
elementFormDefault="qualified">
<xsd:simpleType name="three_datelist">
<xsd:list base="xsd:date">
<xsd:length value="3" />
</xsd:list>
</xsd:simpleType>
<xsd:element name="list_of_3_birthdays" type="three_datelist" />
</xsd:schema>
File: Data.xml
<?xml version="1.0"?>
<list_of_3_birthdays>1893-04-20 1904-05-11
1852-06-25</list_of_3_birthdays>
The list method uses a finite sequence of itemType attributes to derive a new type
<!-- schema -->
<simpleType name="websafe_hex">
<list itemType="string"/>
</simpleType>
<!-- instance document -->
<color xsi:type="websafe_hex"> 00 33 66 99 cc ff</color>
Using a <list> declaration, you can base your list items on a specific <simpleType>
<list itemType="name of simpleType used for validating items in the list">
You specify the type of items by including the itemType attribute.
itemType attribute should be a reference to a global <simpleType> definition or built-in XML Schema datatype.
The <list> declaration allows you to specify your itemType by creating a local <simpleType> definition.
<simpleType name="ContactTagsType">
<restriction base="string">
<enumeration value="author" />
<enumeration value="xml" />
<enumeration value="poetry" />
<enumeration value="consultant" />
<enumeration value="CGI" />
<enumeration value="semantics" />
<enumeration value="employees" />
</restriction>
</simpleType>
<list> declaration:
<simpleType name="ContactTagsListType">
<list itemType="contacts:ContactTagsType"/>
</simpleType>