XML Tutorial/XML Schema/minLength — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 11:26, 26 мая 2010
minLength and maxLength facets are the minimum and maximum number of units permitted for the data type
<source lang="xml">
<?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:simpleType name="USA_LicensePlate"> <xs:restriction base="xs:string"> <xs:minLength value="1" /> <xs:maxLength value="9" /> </xs:restriction> </xs:simpleType>
</xs:schema> Any of the following values would therefore be valid for an element declared to use the USA_LicensePlate datatype: <LicensePlate>123456789</LicensePlate> <LicensePlate>1ABC123</LicensePlate> <LicensePlate>ABC-1234</LicensePlate> <LicensePlate>LICENSE42</LicensePlate></source>
minLength defines the minimum number of units of length using a nonnegative integer
<source lang="xml">
<xsd:simpleType name="productCodeType">
<xsd:restriction base="xsd:string"> <xsd:minLength value="5"/> </xsd:restriction>
</xsd:simpleType></source>
To specify the minimum length of an element:
<source lang="xml">
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="description"> <xsd:simpleType> <xsd:restriction base="xsd:string"> <xsd:minLength value="200" /> </xsd:restriction> </xsd:simpleType> </xsd:element>
</xsd:schema>
File: Data.xml <description xmlns="http://www.wbex.ru"> test</description></source>