Mark Knowledge of XSD

来源:互联网 发布:怎么用js写日期 编辑:程序博客网 时间:2024/04/29 09:42

XSD In The World

XML is very popular of programme project. We use it store configuration and transfer data. How to check it is valid? XSD will give us answer.

What Is XSD?

XSD is XML Schema , it defined struct of XML document.
A XSD schema file has a root element schema, it’s namespace is provided with the schema to tell the XML parser that it is an XSD Schema.

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"></xsd:schema>

Simple Type

XSD Element

<xsd:element name="age" type="xsd:integer"/>
attribute description name Specifies the name of element type Specifies the type of element default Assign a default value to element fix Assign a un changed value to element

XSD Attribute

<xs:attribute name="age" type="xsd:integer"/>
attribute description name Specifies the name of element type Specifies the type of element default Assign a default value to element fix Assign a un changed value to element use “required” for should exist

XSD Restriction
Simple type can specify User-defined data types in XML Schema.

<xsd:simpleType name="phone">    <xsd:restriction base="xsd:string">        <xsd:length value="11">        <xsd:pattern value="\d{3}\-\d{8}"/>    </xsd:restriction></xsd:simpleType> 
Restriction Descrption enumeration define a list of vaild vaule fractionDigits Define the allowed maximum decimal digits length Define char length maxExclusive Numeric values the upper limit of the allowed value must be less than this value maxInclusive Numeric values the upper limit of the allowed value must be less than or equal to this value maxLength Define the allowed maximum number of characters or list items minExclusive Numeric values the lower limit of the allowed value must be greater than this value minInclusive Numeric values the lower limit of the allowed values must be greater than or equal to this value minLength Define the allowed minimum number of characters or list items pattern Definition of acceptable the precise sequence of characters totalDigits Define allowed by the Arabic numerals precise figures whiteSpace Definition blank characters are handle

2. Complex Type

XSD complex element

<xs:element name="employee">  <!--define type directly-->  <xs:complexType>    <xs:sequence>      <xs:element name="firstname" type="xs:string"/>      <xs:element name="lastname" type="xs:string"/>    </xs:sequence>  </xs:complexType></xs:element>

or

<xs:element name="employee" type="personinfo"/><xs:complexType name="personinfo">  <xs:sequence>    <xs:element name="firstname" type="xs:string"/>    <xs:element name="lastname" type="xs:string"/>  </xs:sequence></xs:complexType>

and

<xs:element name="employee" type="fullpersoninfo"/><xs:complexType name="personinfo">  <xs:sequence>    <xs:element name="firstname" type="xs:string"/>    <xs:element name="lastname" type="xs:string"/>  </xs:sequence></xs:complexType><xs:complexType name="fullpersoninfo">  <xs:complexContent>    <!--extension for more information-->    <xs:extension base="personinfo">      <xs:sequence>        <xs:element name="address" type="xs:string"/>        <xs:element name="city" type="xs:string"/>        <xs:element name="country" type="xs:string"/>      </xs:sequence>    </xs:extension>  </xs:complexContent></xs:complexType>
0 0