際際滷

際際滷Share a Scribd company logo
1
XML
Mrs.C.Santhiya
AP/IT
TCE,Madurai.
xsd
 Schema --- 1.Simple type(no child,attributes)
 restriction,built in data types.
 2.Complex type(can contain)
 Simple content----no child,extension,restriction.
 Complex content------child,no limitations
2
syntax
 <?xml version="1.0"?>
<xs:schema>
...
...
</xs:schema>
3
Top Layer
 <?xml version="1.0"?>
<note xmlns="https://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance"
xsi:schemaLocation="https://www.w3schools.com
note.xsd">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
4
XSD-Schema
 Syntax
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="x" type="y"/>
<xs:attribute name="x" type="y"/>
Example
Simple Type
<xs:element name="age">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="100"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
5
Restriction
6
<xs:element name="choice">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[xyz]"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
 <xs:element name="letter">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="([a-z])*"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
7
Complex type
 <product pid="1345"/>
 <employee>
<firstname>John</firstname>
<lastname>Smith</lastname>
</employee>
 <food type="dessert">Ice cream</food>
 <description>
It happened
on <date lang="norwegian">03.03.99</date> ....
</description>
8
1.Variety
 <employee>
<firstname>John</firstname>
<lastname>Smith</lastname>
</employee>
 <xs:elementname="employee">
<xs:complexType>
<xs:sequence>
<xs:elementname="firstname"type="xs:string"/>
<xs:elementname="lastname"type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
9
2.Variety
 <xs:elementname="employee"type="personinfo"/>
<xs:elementname="student"type="personinfo"/>
<xs:elementname="member"type="personinfo"/>
<xs:complexTypename="personinfo">
<xs:sequence>
<xs:elementname="firstname"type="xs:string"/>
<xs:elementname="lastname"type="xs:string"/>
</xs:sequence>
</xs:complexType>
10
3.
 <xs:elementname="employee"type="fullpersoninfo"/>
<xs:complexTypename="personinfo">
<xs:sequence>
<xs:elementname="firstname"type="xs:string"/>
<xs:elementname="lastname"type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexTypename="fullpersoninfo">
<xs:complexContent>
<xs:extensionbase="personinfo">
<xs:sequence>
<xs:elementname="address"type="xs:string"/>
<xs:elementname="city"type="xs:string"/>
<xs:elementname="country"type="xs:string"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
11
 <letter>
DearMr.<name>JohnSmith</name>.
Yourorder<orderid>1032</orderid>
willbeshippedon<shipdate>2001-07-13</shipdate>.
</letter>
 <xs:elementname="letter">
<xs:complexTypemixed="true">
<xs:sequence>
<xs:elementname="name"type="xs:string"/>
<xs:elementname="orderid"type="xs:positiveInteger"/>
<xs:elementname="shipdate"type="xs:date"/>
</xs:sequence>
</xs:complexType>
</xs:element>
12
 <xs:elementname="letter"type="lettertype"/>
<xs:complexTypename="lettertype"mixed="true">
<xs:sequence>
<xs:elementname="name"type="xs:string"/>
<xs:elementname="orderid"type="xs:positiveInteger"/>
<xs:elementname="shipdate"type="xs:date"/>
</xs:sequence>
</xs:complexType>
13
Indicators
Orderindicators:
All
Choice
Sequence
Occurrenceindicators:
maxOccurs
minOccurs
Groupindicators:
Groupname
attributeGroupname
14
All
 <xs:elementname="person">
<xs:complexType>
<xs:all>
<xs:elementname="firstname"type="xs:string"/>
<xs:elementname="lastname"type="xs:string"/>
</xs:all>
</xs:complexType>
</xs:element>
15
choice
 <xs:elementname="person">
<xs:complexType>
<xs:choice>
<xs:elementname="employee"type="employee"/>
<xs:elementname="member"type="member"/>
</xs:choice>
</xs:complexType>
</xs:element>
16
Sequence
 <xs:elementname="person">
<xs:complexType>
<xs:sequence>
<xs:elementname="firstname"type="xs:string"/>
<xs:elementname="lastname"type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
17
maxoccur
 <xs:elementname="person">
<xs:complexType>
<xs:sequence>
<xs:elementname="full_name"type="xs:string"/>
<xs:elementname="child_name"type="xs:string"m
axOccurs="10"/>
</xs:sequence>
</xs:complexType>
</xs:element>
18
minoccurs
 <xs:elementname="person">
<xs:complexType>
<xs:sequence>
<xs:elementname="full_name"type="xs:string"/>
<xs:elementname="child_name"type="xs:string"
maxOccurs="10"minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
19
Ex-xml file
 <?xmlversion="1.0"encoding="UTF-8"?>
<personsxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="family.xsd">
<person>
<full_name>HegeRefsnes</full_name>
<child_name>Cecilie</child_name>
</person>
<person>
<full_name>ToveRefsnes</full_name>
<child_name>Hege</child_name>
<child_name>Stale</child_name>
<child_name>Jim</child_name>
<child_name>Borge</child_name>
</person>
<person>
<full_name>StaleRefsnes</full_name>
</person>
</persons>
20
.xsd file
 <?xmlversion="1.0"encoding="UTF-8"?>
<xs:schemaxmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:elementname="person">
<xs:complexType>
<xs:sequence>
<xs:elementname="person"maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:elementname="full_name"type="xs:string"/>
<xs:elementname="child_name"type="xs:string"
minOccurs="0"maxOccurs="5"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
21
Group Indicators
 <xs:groupname="groupname">
...
</xs:group>
 <xs:groupname="persongroup">
<xs:sequence>
<xs:elementname="firstname"type="xs:string"/>
<xs:elementname="lastname"type="xs:string"/>
<xs:elementname="birthday"type="xs:date"/>
</xs:sequence>
</xs:group>
22
Group reference
 <xs:groupname="persongroup">
<xs:sequence>
<xs:elementname="firstname"type="xs:string"/>
<xs:elementname="lastname"type="xs:string"/>
<xs:elementname="birthday"type="xs:date"/>
</xs:sequence>
</xs:group>
<xs:elementname="person"type="personinfo"/>
<xs:complexTypename="personinfo">
<xs:sequence>
<xs:groupref="persongroup"/>
<xs:elementname="country"type="xs:string"/>
</xs:sequence>
</xs:complexType>
23
 <xs:attributeGroupname="groupname">
...
</xs:attributeGroup>
 <xs:attributeGroupname="personattrgroup">
<xs:attributename="firstname"type="xs:string"/>
<xs:attributename="lastname"type="xs:string"/>
<xs:attributename="birthday"type="xs:date"/>
</xs:attributeGroup>
24
Attr Reference
 <xs:attributeGroupname="personattrgroup">
<xs:attributename="firstname"type="xs:string"/>
<xs:attributename="lastname"type="xs:string"/>
<xs:attributename="birthday"type="xs:date"/>
</xs:attributeGroup>
<xs:elementname="person">
<xs:complexType>
<xs:attributeGroupref="personattrgroup"/>
</xs:complexType>
</xs:element>
25
<any> Element
 <xs:elementname="person">
<xs:complexType>
<xs:sequence>
<xs:elementname="firstname"type="xs:string"/>
<xs:elementname="lastname"type="xs:string"/>
<xs:anyminOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
26
Any attribute
 <xs:elementname="person">
<xs:complexType>
<xs:sequence>
<xs:elementname="firstname"type="xs:string"/>
<xs:elementname="lastname"type="xs:string"/>
</xs:sequence>
<xs:anyAttribute/>
</xs:complexType>
</xs:element>
27
 <?xmlversion="1.0"encoding="UTF-8"?>
<xs:schemaxmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="https://www.w3schools.com"
xmlns="https://www.w3schools.com"
elementFormDefault="qualified">
<xs:attributename="eyecolor">
<xs:simpleType>
<xs:restrictionbase="xs:string">
<xs:patternvalue="blue|brown|green|grey"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:schema>
28
substitutionGroup
 <xs:elementname="name"type="xs:string"/>
<xs:elementname="navn"substitutionGroup="name"/>
29
xml
 <?xmlversion=1.0>
<computer:laptopxmlns:computer=manufacturer=IBM>
<processormodel=centrino>Intel</processor>
<monitor>17</monitor>
<cpuspeed>2.4</cpuspeed>
<RAM>256</RAM>
</computer:laptop>
30
Complex type
 <xmlversion=1.0>
 <schemaxmlns=http://www.w3.org/2001/XMLSchema
 xmlns:computer=
 targetnamespace=>
 <simpleTypename=gigahertz>
 <restrictionbase=decimal>
 <mininclusivevalue=2.1/>
 </restriction>
 </simpleType>
 <complexTypename=CPU>
 <simpleContent>
 <extensionbase=string>
 <attributename=modeltype=string/>
 </extension>
 </simpleContent>
 </complexType>
31
Complex type
 <complexTypename=portable>
 <all>
 <elementname=processortype=computer:cpu/>
 <elementname=monitortype=int/>
 <elementname=CPUSpeedtype=computer:gigahertz/>
 <elementname=RAMtype=int/>
 </all>
 <attributename=manufacturertype=string/>
 </complexType>
 <elementname=laptoptype=computer:portable/>
 </schema>
32

More Related Content

Xml p3 -Lecture Notes