XML/XML Schema/list

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

A list datatype can be done by embedding a xs:simpleType element

File: Data.xml
<?xml version="1.0"?>
<data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://www.wbex.ru Schema.xsd"
              xmlns="http://www.wbex.ru"
              >
  1 2 3   
</data>
File: Schema.xsd
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
  targetNamespace="http://www.wbex.ru" xmlns="http://www.wbex.ru"
  elementFormDefault="qualified">
    <xs:element name="data" type="myIntegerList"/>
  <xs:simpleType name="myIntegerList">
    <xs:list>
      <xs:simpleType>
        <xs:restriction base="xs:integer">
          <xs:maxInclusive value="100" />
        </xs:restriction>
      </xs:simpleType>
    </xs:list>
  </xs:simpleType>
</xs:schema>



Apply a facet constraining the length

File: Data.xml
<?xml version="1.0"?>
<data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://www.wbex.ru Schema.xsd"
              xmlns="http://www.wbex.ru"
              >
  1 2 3   
</data>
File: Schema.xsd
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
  targetNamespace="http://www.wbex.ru" xmlns="http://www.wbex.ru"
  elementFormDefault="qualified">
    <xs:element name="data" type="myRestrictedStringList"/>

  <xs:simpleType name="myStringList">
    <xs:list itemType="xs:string" />
  </xs:simpleType>
  <xs:simpleType name="myRestrictedStringList">
    <xs:restriction base="myStringList">
      <xs:maxLength value="10" />
    </xs:restriction>
  </xs:simpleType>
</xs:schema>



decimal list type

File: Data.xml
<?xml version="1.0"?>
<numbers>12 34.5 18.2 5</numbers>
File: Schema.xsd
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="numbers" type="number-list" />
  <xs:simpleType name="number-list">
    <xs:list itemType="xs:decimal" />
  </xs:simpleType>
</xs:schema>



To define a string datatype of 100 and 200 words, each having a length of less than 15 characters

File: Data.xml
<?xml version="1.0"?>
<data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://www.wbex.ru Schema.xsd"
              xmlns="http://www.wbex.ru"
              >
 one two one two one two one two one two one two one two one two one two one two one two one two
 one two one two one two one two one two one two one two one two one two one two one two one two
 one two one two one two one two one two one two one two one two one two one two one two one two
 one two one two one two one two one two one two one two one two one two one two one two one two
 one two one two one two one two one two one two one two one two one two one two one two one two
 one two one two one two one two one two one two one two one two one two one two one two one two
 one two one two one two one two one two one two one two one two one two one two one two one two
 one two one two one two one two one two two
</data>
File: Schema.xsd

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
  targetNamespace="http://www.wbex.ru" xmlns="http://www.wbex.ru"
  elementFormDefault="qualified">

    <xs:element name="data" type="story"/>

  <xs:simpleType name="word">
    <xs:list>
      <xs:simpleType>
        <xs:restriction base="xs:string">
          <xs:maxLength value="15" />
          <xs:pattern value="\p{IsBasicLatin}*" />
        </xs:restriction>
      </xs:simpleType>
    </xs:list>
  </xs:simpleType>
  <xs:simpleType name="story">
    <xs:restriction base="word">
      <xs:minLength value="100" />
      <xs:maxLength value="200" />
    </xs:restriction>
  </xs:simpleType>
</xs:schema>