XML/XML Schema/whiteSpace

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

xs:whiteSpace defines the way to handle whitespaces

i.e., #x20 (space), #x9 (tab), #xA (linefeed), and #xD (carriage return)
<?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="CapitalizedNameWS">
    <xs:restriction base="xs:string">
      <xs:whiteSpace value="collapse" />
      <xs:pattern value="([A-Z]([a-z]*) ?)+" />
    </xs:restriction>
  </xs:simpleType>
</xs:schema>



xs:whiteSpace defines whitespace and can expand the set of accepted instance documents during a "restriction,"

<?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:simpleType name="greetings">
    <xsd:restriction base="xsd:string">
      <xsd:whiteSpace value="replace" />
      <xsd:enumeration value="hi" />
      <xsd:enumeration value="hello" />
      <xsd:enumeration value="how do you do?" />
    </xsd:restriction>
  </xsd:simpleType>
  <xsd:simpleType name="restricted-greetings">
    <xsd:restriction base="greetings">
      <xsd:whiteSpace value="collapse" />
    </xsd:restriction>
  </xsd:simpleType>
</xsd:schema>