XML Tutorial/XML Schema/maxExclusive

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

Constrain a data type to be a single constant value:

<?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="TheAnswer">
    <xs:restriction base="xs:integer">
      <xs:minInclusive value="42" />
      <xs:maxInclusive value="42" />
    </xs:restriction>
  </xs:simpleType>
</xs:schema>


Element"s content must be lower than (and not equal to) the xsd:maxExclusive value.

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="population">
    <xsd:simpleType>
      <xsd:restriction base="xsd:integer">
        <xsd:maxExclusive value="5000" />
      </xsd:restriction>
    </xsd:simpleType>
  </xsd:element>
</xsd:schema>
 
File: Data.xml
<?xml version="1.0"?>
<population xmlns="http://www.wbex.ru">5000</population>


maxExclusive Defines the exclusive upper bound for a datatype with the ordered property

<xsd:simpleType name="upperType">
  <xsd:restriction base="integer">
   <xsd:maxExclusive value="101"/>
  </xsd:restriction>
</xsd:simpleType>


minExclusive, minInclusive, maxExclusive, maxInclusive

<?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="negativeInteger">
    <xs:annotation>
      <xs:documentation source="http://www.w3.org/TR/xmlschema-2/#negativeInteger" />
    </xs:annotation>
    <xs:restriction base="xs:nonPositiveInteger">
      <xs:maxInclusive value="-1"/>
    </xs:restriction>
  </xs:simpleType>
</xs:schema>