summary_xsd

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

------------------------------------------------------------
--------------OUTLINE-------------
------------------------------------------------------------
DTD XML
DTD XML Schema data type namespace
------------------------------------------------------------
--------------XML XSD
<?xml version="1.0"?>
<note
xmlns="" <!-- schema xml -->
xmlns:xsi="/2001/XMLSchema-instance" < --- DTD ->
xsi:schemaLocation=" note.xsd">
< --- xml schema ->
< --- XML Schema -->
<to>George</to>
<from>John</from>
<heading>Reminder</heading>
<body>Don't forget the meeting!</body>
</note>
------------------------------------------------------------
--------------XSD
<?xml version="1.0"?>
<xs:schema xmlns:xs="/2001/XMLSchema" <!-- xs-->
targetNamespace="" <!-- schema -->
xmlns="" <!-- -->
elementFormDefault="qualified"> <!-- XML schema -->
<xs:element name="note">
<xs:complexType> <!-- -->
<xs:sequence>
<xs:element name="to" type="xs:string"/> <!-- -->
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
------------------------------------------------------------
--------------XSD -------------
------------------------------------------------------------
<schema> XML Schema
------------------------------------------------------------
--------------XSD
xml shema
xs:string
xs:decimal
xs:integer
xs:boolean
xs:date
xs:time
------------------------------------------------------------
--------------
:
,
<xs:element name="color" type="xs:string" default="red"/>
<xs:element name="color" type="xs:string" fixed="red"/>
----
----
<xs:attribute name="xxx" type="yyy"/>
<xs:attribute name="lang" type="xs:string" default="EN"/>
<xs:attribute name="lang" type="xs:string" fixed="EN"/>
----
"use"
<xs:attribute name="lang" type="xs:string" use="required"/>
------------------------------------------------------------
--------------
XML shema ( )
facets
restriction XML facet
<xs:element name="age"><!-- -->
<xs:simpleType><!-- -->
<xs:restriction base="xs:integer"><!-- -->
<xs:minInclusive value="0"/>**
<xs:maxInclusive value="120"/>**
</xs:restriction>
</xs:simpleType>
</xs:element>
----
XML enumeration constraint Audi, Golf, BMW
<xs:element name="car">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Audi"/>**
<xs:enumeration value="Golf"/>**
<xs:enumeration value="BMW"/>**
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="car" type="carType"/>
<xs:simpleType name="carType">
<xs:restriction base="xs:string">
<xs:enumeration value="Audi"/>
<xs:enumeration value="Golf"/>
<xs:enumeration value="BMW"/>
</xs:restriction>
</xs:simpleType>
"carType" "car"
------------------
XML pattern constraint
a - z
<xs:element name="letter">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-z]"/>**
</xs:restriction>
</xs:simpleType>
</xs:element>
A - Z <xs:pattern value="[A-Z][A-Z][A-Z]"/>**
a - z <xs:pattern value="[a-zA-Z][a-zA-Z][a-zA-Z]"/>**
x, y z <xs:pattern value="[xyz]"/>
0-9:
<xs:restriction base="xs:integer">
<xs:pattern value="[0-9][0-9][0-9][0-9][0-9]"/>**
</xs:restriction>
a - z :
<xs:restriction base="xs:string">
<xs:pattern value="([a-z])*"/>**
</xs:restriction>
"sToP" "Stop" "STOP" "stop"
<xs:restriction base="xs:string">
<xs:pattern value="([a-z][A-Z])+"/>
</xs:restriction>
male female
<xs:restriction base="xs:string">
<xs:pattern value="male|female"/>
</xs:restriction>
8 a - z 0 - 9
<xs:restriction base="xs:string">
<xs:pattern value="[a-zA-Z0-9]{8}"/>
</xs:restriction>
------------------------------------------------------------
--------------
whitespace characters whiteSpace
<xs:restriction base="xs:string">
<xs:whiteSpace value="preserve"/>**
</xs:restriction>
whiteSpace "preserve" XML
<xs:restriction base="xs:string">
<xs:whiteSpace value="replace"/>
</xs:restriction>
whiteSpace "replace" XML
<xs:restriction base="xs:string">
<xs:whiteSpace value="collapse"/>
</xs:restriction>
whiteSpace "collapse" XML
------------------------------------------------------------
--------------
length maxLength minLength
8
<xs:restriction base="xs:string">
<xs:length value="8"/>
</xs:restriction>
5 8
<xs:restriction base="xs:string">
<xs:minLength value="5"/>
<xs:maxLength value="8"/>
</xs:restriction>
------------------------------------------------------------
--------------
enumeration
fractionDigits 0
length 0 maxExclusive maxInclusive maxLength 0 minExclusive
minInclusive minLength 0 pattern
totalDigits 0 whiteSpace
------------------------------------------------------------
-------------
/ XML
:
1.
2.
3. ( )
4.
-------
1. <product pid="1345"/>
2.
<employee>
<firstname>John</firstname>
<lastname>Smith</lastname>
</employee>
3. <food type="dessert">Ice cream</food>
4.
<description>
It happened on <date lang="norwegian">03.03.99</date> ....
</description>
------------------------------------------------------------
-------------
xml schema
1. "employee"
<xs:element name="employee"><!-- -->
<xs:complexType><!-- -->
<xs:sequence><!-- -->
<xs:element name="firstname" type="xs:string"/><!-- -->
<xs:element name="lastname" type="xs:string"/><!-- -->
</xs:sequence>
</xs:complexType>
</xs:element>
"employee"
"firstname" "lastname" <sequence>
2."employee" type
<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>
<xs:element name="employee" type="personinfo"/>
<xs:element name="student" type="personinfo"/>
<xs:element name="member" 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>
<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:complexType>
<xs:complexType name="fullpersoninfo">
<xs:complexContent><!-- , -->
<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>
------------------------------------------------------------
-------------1/4
<product prodid="1345" />
"product"
<xs:element name="product">
<xs:complexType>
<xs:complexContent><!-- , -->
<xs:restriction base="xs:integer">
<xs:attribute name="prodid" type="xs:positiveInteger"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
complexContent [ ] [ ] integer
"product"
<xs:element name="product">
<xs:complexType>
<xs:attribute name="prodid" type="xs:positiveInteger"/>
</xs:complexType>
</xs:element>
complexType "product" type complexType
<xs:element name="product" type="prodtype"/>
<xs:complexType name="prodtype">
<xs:attribute name="prodid" type="xs:positiveInteger"/>
</xs:complexType>
------------------------------------------------------------
-------------2/4
<person>
<firstname>John</firstname>
<lastname>Smith</lastname>
</person>
schema "person"
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:sequence> "person"
complexType "person" type
<xs:element name="person" type="persontype"/>
<xs:complexType name="persontype">
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:sequence>
</xs:complexType>
------------------------------------------------------------
-------------3/4
simpleContent
simpleContent
<xs:element name=" ">
<xs:complexType>
<xs:simpleContent><!-- -->
<xs:extension base="basetype">
....
....
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name=" ">
<xs:complexType>
<xs:simpleContent>
<xs:restriction base="basetype">
....
....
</xs:restriction>
</xs:simpleContent>
</xs:complexType>
</xs:element>
extension restriction
XML "shoesize"
<shoesize country="france">35</shoesize>
"shoesize" "country"
<xs:element name="shoesize">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:integer"><!-- -->
<xs:attribute name="country" type="xs:string" /><!-- -->
</xs:simpleContent>
</xs:complexType>
</xs:element>
complexType "shoesize" type
<xs:element name="shoesize" type="shoetype"/>
<xs:complexType name="shoetype">
<xs:simpleContent>
<xs:extension base="xs:integer">
<xs:attribute name="country" type="xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
------------------------------------------------------------
-------------4/4
XML "letter"
<letter>
Dear Mr.<name>John Smith</name>.
Your order <orderid>1032</orderid>
will be shipped on <shipdate>2001-07-13</shipdate>.
</letter>
schema "letter"
<xs:element name="letter">
<xs:complexType mixed="true"><!-- -->
<xs:element name="name" type="xs:string"/>
<xs:element name="orderid" type="xs:positiveInteger"/>
<xs:element name="shipdate" type="xs:date"/>
</xs:sequence>
</xs:complexType>
</xs:element>
"letter" mixed "true"
<xs:sequence> (name orderid shipdate ) "letter"
complexType "letter" type complexType
<xs:element name="letter" type="lettertype"/>
<xs:complexType name="lettertype" mixed="true">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="orderid" type="xs:positiveInteger"/>
<xs:element name="shipdate" type="xs:date"/>
</xs:sequence>
</xs:complexType>
------------------------------------------------------------
-------------XSD
XSD
1.Order 3
All
Choice
Sequence
2.Occurrence 2
maxOccurs
minOccurs
3.Group 2
Group name
attributeGroup name
------------------------------------------------------------
-------------1/3Order
Order
All
<all> <xs:element name="person">
<xs:complexType>
<xs:all><!-- -->
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:all>
</xs:complexType>
</xs:element>
<all> <minOccurs> 0 1 <maxOccurs> 1 <minOccurs> <maxOccurs>
--------------------
Choice
<choice>
<xs:element name="person">
<xs:complexType>
<xs:choice><!-- -->
<xs:element name="employee" type="employee"/>
<xs:element name="member" type="member"/>
</xs:choice>
</xs:complexType>
</xs:element>
--------------------
Sequence
<sequence>
<xs:element name="person">
<xs:complexType>
<xs:sequence><!-- -->
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
------------------------------------------------------------
-------------2/3Occurrence
Occurrence
Occurrence
"Order" "Group" any all choice sequence group name group reference maxOccurs minOccurs 1
--------------------
maxOccurs
<maxOccurs>
<xs:element name="person">
<xs:complexType>
<xs:sequence><!-- -->
<xs:element name="full_name" type="xs:string"/>
<xs:element name="child_name" type="xs:string" maxOccurs="10"/><!-- -->
</xs:sequence>
</xs:complexType>
</xs:element>
"child_name" "person" minOccurs 1 10
--------------------
minOccurs
<minOccurs>
<xs:element name="person">
<xs:complexType>
<xs:sequence><!-- -->
<xs:element name="full_name" type="xs:string"/>
<xs:element name="child_name" type="xs:string"
maxOccurs="10" minOccurs="0"/> <!-- -->
</xs:sequence>
</xs:complexType>
</xs:element>
"child_name" "person" 0 10 --------------------
maxOccurs="unbounded"
"Myfamily.xml" XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<persons xmlns:xsi="/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="family.xsd">
<person>
<full_name>Tony Smith</full_name>
<child_name>Cecilie</child_name>
</person>
<person>
<full_name>David Smith</full_name>
<child_name>Jogn</child_name>
<child_name>mike</child_name>
<child_name>kyle</child_name>
<child_name>mary</child_name>
</person>
<person>
<full_name>Michael Smith</full_name>
</person>
</persons>
XML "persons" "person" "person" "full_name" 5 "child_name"
schema "family.xsd"
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="persons">
<xs:complexType>
<xs:sequence><!-- -->
<xs:element name="person" maxOccurs="unbounded"><!-- -->
<xs:complexType>
<xs:sequence><!-- -->
<xs:element name="full_name" type="xs:string"/>
<xs:element name="child_name" type="xs:string"
minOccurs="0" maxOccurs="5"/><!-- -->
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
------------------------------------------------------------
-------------3/3Group
Group
------------------------------------------------------------
-------------
group
<xs:group name=" ">
...
</xs:group>
group all choice sequence (Order )
"persongroup" group <xs:group name="persongroup">
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
<xs:element name="birthday" type="xs:date"/>
</xs:sequence>
</xs:group>
group <xs:group name="persongroup">
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
<xs:element name="birthday" type="xs:date"/>
</xs:sequence>
</xs:group>
<xs:element name="person" type="personinfo"/>
<xs:complexType name="personinfo">
<xs:sequence>
<xs:group ref="persongroup"/><!-- -->
<xs:element name="country" type="xs:string"/>
</xs:sequence>
</xs:complexType>
------------------------------------------------------------
-------------
attributeGroup
<xs:attributeGroup name=" ">
...
</xs:attributeGroup>
"personattrgroup"
<xs:attributeGroup name="personattrgroup">
<xs:attribute name="lastname" type="xs:string"/>
<xs:attribute name="birthday" type="xs:date"/>
</xs:attributeGroup>
<xs:attributeGroup name="personattrgroup">
<xs:attribute name="firstname" type="xs:string"/>
<xs:attribute name="lastname" type="xs:string"/>
<xs:attribute name="birthday" type="xs:date"/>
</xs:attributeGroup>
<xs:element name="person">
<xs:complexType>
<xs:attributeGroup ref="personattrgroup"/>
</xs:complexType>
</xs:element>
------------------------------------------------------------
-------------XSD<any>
<any> schema XML
<any> <lastname> "person" "family.xsd" XML schema
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:any minOccurs="0"/><!--any -->
</xs:sequence>
</xs:complexType>
</xs:element>
"children" "person" schema "children"
schema "children.xsd"
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="/2001/XMLSchema"
targetNamespace=""
xmlns=""
elementFormDefault="qualified">
<xs:element name="children">
<xs:complexType>
<xs:sequence>
<xs:element name="childname" type="xs:string"
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
XML "Myfamily.xml" schema "family.xsd" "children.xsd"
<?xml version="1.0" encoding="ISO-8859-1"?>
<persons xmlns=""
xmlns:xsi="/2001/XMLSchema-instance"
xsi:SchemaLocation=" family.xsd <!-- xsd -->
children.xsd"><!-- xsd -->
<person>
<firstname>David</firstname>
<lastname>Smith</lastname>
<children>
<childname>mike</childname>
</children>
</person>
<person>
<firstname>Tony</firstname>
<lastname>Smith</lastname>
</person>
</persons>
XML schema "family.xsd" "lastname" "person"
<any> <anyAttribute> XML schema
------------------------------------------------------------
-------------XSD<anyAttribute>
<anyAttribute> schema XML
"family.xsd" XML schema <anyAttribute> "person"
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:sequence>
<xs:anyAttribute/><!-- -->
</xs:complexType>
</xs:element>
"gender" "person" schema "gender"
schema "attribute.xsd"
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="/2001/XMLSchema"
targetNamespace=""
xmlns=""
elementFormDefault="qualified">
<xs:attribute name="gender">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="male|female"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:schema>
XML "Myfamily.xml" schema "family.xsd" "attribute.xsd"
<?xml version="1.0" encoding="ISO-8859-1"?>
<persons xmlns=""
xmlns:xsi="/2001/XMLSchema-instance"
xsi:SchemaLocation=" family.xsd
attribute.xsd">
<person gender="female">
<firstname>Jane</firstname>
<lastname>Smith</lastname>
</person>
<person gender="male">
<firstname>David</firstname>
<lastname>Smith</lastname>
</person>
</persons>
XML schema "family.xsd" "person"
any> <anyAttribute> XML schema
------------------------------------------------------------
-------------XSD Element Substitution
xsd
XML
XML schema substitutionGroup
<xs:element name="name" type="xs:string"/>
<xs:element name="navn" substitutionGroup="name"/>
"name" "navn" "name"
XML schema
<xs:element name="name" type="xs:string"/>
<xs:element name="navn" substitutionGroup="name"/><!-- -->
<xs:complexType name="custinfo">
<xs:sequence>
<xs:element ref="name"/>
</xs:sequence>
</xs:complexType>
<xs:element name="customer" type="custinfo"/>
<xs:element name="kunde" substitutionGroup="customer"/><!-- -->
XML schema
<customer>
<name>John Smith</name>
</customer>
<kunde>
<navn>John Smith</navn>
</kunde>
substitutionGroup
substitutionGroup
------------------------------------------------------------
-------------
block
<xs:element name="name" type="xs:string" block="substitution"/>
XML schema
<xs:element name="name" type="xs:string" block="substitution"/>
<xs:element name="navn" substitutionGroup="name"/>
<xs:complexType name="custinfo">
<xs:sequence>
<xs:element ref="name"/>
</xs:sequence>
</xs:complexType>
<xs:element name="customer" type="custinfo" block="substitution"/>
<xs:element name="kunde" substitutionGroup="customer"/>
------------------------------------------------------------
------------- Global Elements
"schema" Local elements
------------------------------------------------------------
--------------XSD -------------
------------------------------------------------------------
------------------------------------------------------------
-------------xsd String Data Type
<xs:element name="customer" type="xs:string"/>
<customer>John Smith</customer>
<customer> John Smith </customer>
XML
-------------
NormalizedString Data Type
XML
<xs:element name="customer" type="xs:normalizedString"/>
<customer>John Smith</customer>
<customer> John Smith </customer>
XML
-------------
Token Token Data Type
XML
<xs:element name="customer" type="xs:token"/>
<customer>John Smith</customer>
<customer> John Smith </customer>
XML
-------------
ENTITIES
ENTITY
ID XML ID ( schema )
IDREF XML IDREF ( schema )
IDREFS language id
Name XML
NCName
NMTOKEN XML NMTOKEN ( schema )
NMTOKENS
normalizedString
QName
string
token
-------------。

相关文档
最新文档