XML/XML Schema/list
Версия от 21:22, 25 мая 2010; (обсуждение)
Содержание
A list datatype can be done by embedding a xs:simpleType element
<source lang="xml">
File: Data.xml <?xml version="1.0"?>
1 2 3
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>
</source>
Apply a facet constraining the length
<source lang="xml">
File: Data.xml <?xml version="1.0"?>
1 2 3
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>
</source>
decimal list type
<source lang="xml">
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>
</source>
To define a string datatype of 100 and 200 words, each having a length of less than 15 characters
<source lang="xml">
File: Data.xml <?xml version="1.0"?>
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
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>
</source>