XML Tutorial/XML Schema/list

Материал из Web эксперт
Перейти к: навигация, поиск

A list data type is derived from an atomic data type that allows white space

<!-- schema -->
<simpleType name="myLuckyNumbers">
  <list itemType="decimal"/>
<!-- 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"/>
<!-- instance document -->
<string_list xsi:type="myString">
  This string is a 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"
  <xsd:simpleType name="three_datelist">
    <xsd:list base="xsd:date">
      <xsd:length value="3" />
  <xsd:element name="list_of_3_birthdays" type="three_datelist" />
File: Data.xml
<?xml version="1.0"?>
<list_of_3_birthdays>1893-04-20 1904-05-11

The list method uses a finite sequence of itemType attributes to derive a new type

<!-- schema -->
<simpleType name="websafe_hex">
  <list itemType="string"/>
<!-- 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" />

<list> declaration: 
<simpleType name="ContactTagsListType"> 
    <list itemType="contacts:ContactTagsType"/>