W3C XML Schema 内建字符串类型比较

W3C XML Schema 内建字符串类型比较(含schema及xml文件)
string,字符串。 
  可以包含回车符,换行符,制表符.
QName (qualified name),有前缀名称类型。
  前缀和局部名称必须都是NCName类型,中间用冒号连接.
normalizedString,规范化字符串类型。
  string中回车符、换行符、制表符将被去掉 。
token,记号字符串类型。
  normalizedString中头、尾及中间多余的空格字符将被去掉。
NMTOKEN,名称记号字符串类型。
  限制 token 类型中只能包含数字, 字母, 下划线, 冒号, 及其他名字字符 (可以由数字开头 )
name,名称字符串类型。
  限制 token 类型中只包含数字, 字母, 下划线, 冒号, 及其他名字字符, 且非数字开头
NCName,无冒号名称字符串类型。
  限制name类型中不含冒号

 

这里提供一个schema和它的一个xml,来说明W3C XML Schema 各种内建字符串类型的区别。欢迎大家添加更有趣的例子。

charTypes.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- by 98900969r. to compare various XML Schema built-in string-based simple types. -->
<!-- 把被注释的不合法例子“放出来”,就会有验证错误 -->
<strings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="charTypes.xsd">
 <primitiveTypes>
 
  <!-- string,字符串。 可以包含回车符,换行符,制表符 -->
  <string>
        */??:123abc?          ???@#$%*()_+      +=-{}|/~!,.;:
                                    </string>
  
  <!-- QName (qualified name),有前缀名称类型。前缀和局部名称必须都是NCName类型,中间用冒号连接 -->
  <QName>q:a1234</QName>
  
  <!-- invalid QName, 不合法例子
  <QName>q:?abc</QName>
  <QName>q:*abc</QName>
  <QName>q: abc</QName>
  <QName>q:1abc</QName>
  -->
 </primitiveTypes>
 <derivedTypes>
 
  <!--  normalizedString,规范化字符串类型。string中回车符、换行符、制表符将被去掉 。-->
  <normalizedString>  */??:123abc?          ???@#$%*()_+      +=-{}|/~!,.;:</normalizedString>
  
  <!-- token,记号字符串类型。normalizedString中头、尾及中间多余的空格字符将被去掉。-->
  <token>*/??:123abc? ???@#$%*()_+ +=-{}|/~!,.;:</token>
  
  <!-- NMTOKEN,名称记号字符串类型。
  限制 token 类型中只能包含数字, 字母, 下划线, 冒号, 及其他名字字符 (可以由数字开头 ) -->
  <NMTOKEN>:1234</NMTOKEN>
  <NMTOKEN>_1234</NMTOKEN>
  
  <!-- invalid NMTOKEN,不合法例子
  <NMTOKEN>?asdfsad</NMTOKEN>
  <NMTOKEN>*1223a</NMTOKEN>
  <NMTOKEN>?1234</NMTOKEN>
  <NMTOKEN>a1234?</NMTOKEN>
  <NMTOKEN>/a1234</NMTOKEN>
  <NMTOKEN>)a1234</NMTOKEN>
  <NMTOKEN>$a1234</NMTOKEN>
  <NMTOKEN>_12 34</NMTOKEN>
  -->
  
  <!-- name,名称字符串类型。限制 token 类型中只包含数字, 字母, 下划线, 冒号, 及其他名字字符, 且非数字开头 -->
  <Name>:1234</Name>
  <Name>q:123a</Name>
  
  <!-- invalid Name 不合法例子
  <Name>1234</Name>
  -->
  
  <!-- NCName,无冒号名称字符串类型。限制name类型中不含冒号 -->
   
  <NCName>_1234</NCName>
  <NCName>abcd123</NCName>
  <NCName>书名1</NCName>
  
  <!-- invalid NCName  不合法例子
  <NCName>:123a</NCName>
  <NCName>q:123a</NCName>
  -->
 </derivedTypes>
</strings>

 

charTypes.xsd

<?xml version="1.0" encoding="UTF-8"?>
<!-- by 98900969r. to compare various XML Schema built-in string-based simple types. -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
 <xs:annotation>
  <xs:documentation>
  references:
  [1] Primitive XML Data Types
  http://doc.ddart.net/xmlsdk/htm/xsd_ref_6ldf.htm
  [2] Derived XML Data Types
  http://doc.ddart.net/xmlsdk/htm/xsd_ref_6z03.htm
  [3] w3schools, XML Schema Tutorial : String data types are used for values that contains character strings.
  http://www.w3schools.com/schema/schema_dtypes_string.asp
  </xs:documentation>
 </xs:annotation>
 <xs:element name="strings">
  <xs:complexType>
   <xs:sequence>
    <xs:element name="primitiveTypes">
     <xs:complexType>
      <xs:sequence>
       <!-- string - Represents character strings. -->
       <!-- string,字符串。 可以包含回车符,换行符,制表符 -->
       <xs:element name="string" type="xs:string" maxOccurs="unbounded"/>
       <!-- QName - Represents a qualified name. 
       A qualified name is composed of a prefix and a local name separated by a colon. 
       Both the prefix and local names must be an NCName. 
       The prefix must be associated with a namespace URI reference, using a namespace declaration. -->
       <!-- QName (qualified name),有前缀名称类型。前缀和局部名称必须都是NCName类型,中间用冒号连接 -->
       <xs:element name="QName" type="xs:QName" maxOccurs="unbounded"/>
      </xs:sequence>
     </xs:complexType>
    </xs:element>
    <xs:element name="derivedTypes">
     <xs:complexType>
      <xs:sequence>
       <!-- normalizedString - Represents white space normalized strings. 
       This data type is derived from string. A string that does not contain line feeds, carriage returns, or tabs -->
       <!--  normalizedString,规范化字符串类型。
       string中回车符、换行符、制表符将被去掉 被当成空字符相邻头、尾及中间多余的"空字符"去掉。-->
       <xs:element name="normalizedString" type="xs:normalizedString" maxOccurs="unbounded"/>
       <!--  token - Represents tokenized strings. 
       This data type is derived from normalizedString. 
       A string that does not contain line feeds, carriage returns, tabs, leading or trailing spaces, or multiple spaces -->
       <!-- token,记号字符串类型。normalizedString中头、尾及中间多余的空格字符将被去掉。-->
       <xs:element name="token" type="xs:token" maxOccurs="unbounded"/>
       <!-- NMTOKEN - Represents the NMTOKEN attribute type. 
       An NMTOKEN is set of name characters (letters, digits, and other characters) in any combination. 
       Unlike Name and NCName, NMTOKEN has no restrictions on the starting character. 
       This data type is derived from token. (only used with schema attributes) -->
       <!-- NMTOKEN,名称记号字符串类型。
       限制 token 类型中只能包含数字, 字母, 下划线, 冒号, 及其他名字字符 (可以由数字开头 ) -->
       <xs:element name="NMTOKEN" type="xs:NMTOKEN" maxOccurs="unbounded"/>
       <!-- Represents names in XML. 
       A Name is a token that begins with a letter, underscore, or colon and continues with name characters 
       (i.e. letters, digits, and other characters). 
       This data type is derived from token. -->
       <!-- name,名称字符串类型。限制 token 类型中只包含数字, 字母, 下划线, 冒号, 及其他名字字符, 且非数字开头 -->
       <xs:element name="Name" type="xs:Name" maxOccurs="unbounded"/>
       <!-- Represents noncolonized names. This data type is the same as Name, except it cannot begin with a colon. 
       This data type is derived from Name. -->
       <!-- NCName,无冒号名称字符串类型。限制name类型中不含冒号 -->
       <xs:element name="NCName" type="xs:NCName" maxOccurs="unbounded"/>
      </xs:sequence>
     </xs:complexType>
    </xs:element>
   </xs:sequence>
  </xs:complexType>
 </xs:element>
</xs:schema>

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值