XML/XML Schema/restriction
Содержание
Derivation By Restriction
<source lang="xml">
File: Data.xml <?xml version="1.0"?>
1
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="myInteger"/> <xs:simpleType name="myInteger"> <xs:restriction base="xs:integer"> <xs:minInclusive value="-2" /> <xs:maxExclusive value="5" /> </xs:restriction> </xs:simpleType>
</xs:schema>
</source>
restriction on another user-defined type
<source lang="xml">
File: Data.xml <?xml version="1.0"?> <Store xmlns="http://www.wbex.ru"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation= "http://www.wbex.ru testRestriction.xsd"> <Flyer> <Title>title</Title> <Date>2001</Date> </Flyer>
</Store>
File: testRestriction.xsd <?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.wbex.ru" xmlns="http://www.wbex.ru" elementFormDefault="qualified"> <xsd:complexType name="Publication"> <xsd:sequence> <xsd:element name="Title" type="xsd:string" maxOccurs="unbounded"/> <xsd:element name="Author" type="xsd:string" minOccurs="0"/> <xsd:element name="Date" type="xsd:gYear"/> </xsd:sequence> </xsd:complexType> <xsd:complexType name="FlyerType"> <xsd:complexContent> <xsd:restriction base="Publication"> <xsd:sequence> <xsd:element name="Title" type="xsd:string" maxOccurs="unbounded"/> <xsd:element name="Date" type="xsd:gYear"/> </xsd:sequence> </xsd:restriction> </xsd:complexContent> </xsd:complexType> <xsd:element name="Store"> <xsd:complexType> <xsd:sequence> <xsd:element name="Flyer" type="FlyerType" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> </xsd:element>
</xsd:schema>
</source>
restriction on xsd:string
<source lang="xml">
File: Data.xml <?xml version="1.0"?> alpha
File: Schema.xsd
<?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:element name="data" type="myType"/> <xsd:simpleType name="myType"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="alpha"/> <xsd:enumeration value="beta"/> <xsd:enumeration value="gamma"/> </xsd:restriction> </xsd:simpleType>
</xsd:schema>
</source>
using an embedded xs:simpleType(global definition) anonymous definition:
<source lang="xml">
File: Data.xml <?xml version="1.0"?>
1
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="myInteger"/>
<xs:simpleType name="myInteger"> <xs:restriction> <xs:simpleType> <xs:restriction base="xs:integer"> <xs:maxExclusive value="5" /> </xs:restriction> </xs:simpleType> <xs:minInclusive value="-2" /> </xs:restriction> </xs:simpleType>
</xs:schema>
</source>