ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML ©...
-
Upload
reynard-benson -
Category
Documents
-
view
224 -
download
0
Transcript of ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML ©...
![Page 1: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/1.jpg)
ITEC 4020A:Internet Client Server Systems
Professor: Marin LitoiuLecture 9&10 Web Service-XML
© Marin Litoiu, York University, Canada
![Page 2: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/2.jpg)
Web Services-Content
Introduction to XML DTDs and XML Schema Web Services, SOAP, WSDL, VoiceXML
2
![Page 3: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/3.jpg)
Unit 1. Introduction to XML
Learning Objectives Understand how XML is different from HTML Understand the basic things that make up XML
3
![Page 4: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/4.jpg)
<XML> What is XML? </XML>
XML - EXtensible Markup LanguageIt is a meta-markup language
Let’s create our own tagsEx:<name>John</name>
It is a standard for data structuring and interchangeIt is surrounded by TLAs: XSL, DTD, SAX, DOM…
and FRLAs: XSLT, VXML, SOAP…Descends from SGML
4
![Page 5: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/5.jpg)
5
XML is a Meta-Language
(from w3c site)
![Page 6: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/6.jpg)
6
XML is about Structured Data
Unstructured data-natural language description: ”A company has a personnel and the personnel has one or more persons. Persons have name, address, etc…” Structured data: a tree
personnel
person
name
title given family
address
streetMr. John Higgins
zipM3C1H7
person
Wall St.
company
![Page 7: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/7.jpg)
7
Why not HTML?
HTML tags are concerned with rendering XML is concerned with the semantic of information XML is a meta-language, HTML can be seen as an instance of it (XHTML) HTML is one of the presentation formats for XML languages
![Page 8: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/8.jpg)
8
Simple HTML document(1 of 2)
<p>
<b>Helm Brown</b>
<br>
Moon Light
<br>
Toronto
</p>
![Page 9: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/9.jpg)
9
Simple HTML document (2 of 2)
An HTML browser knows how to render
A human can understand each line, can a computer or application?
How easy is to search for a piece of data?
![Page 10: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/10.jpg)
10
Simple XML (PML?)
<?xml version ="1.0"?><person> <name> < title> Mr.</title> < given> Helm </given> <family> Brown </family> </name> <address> <street> Moon Light </street> <zip> M3C1H7 <zip> </address></person>
![Page 11: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/11.jpg)
11
Tags, Elements, CDATA
<?xml version ="1.0"?><person> <name> < title> Mr.</title> < given> Helm </given> <family> Brown </family> </name> <address> <street> Moon Light </street> <zip> M3C1H7 <zip> </address></person>
Start tag
Element
End tag
CDATA
Markup
![Page 12: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/12.jpg)
12
XML Document as a Tree
person
name
title family given
address
street
Mr. Helm Brown
zip
M3C1H7Moon Light
parent
children
CDATA
![Page 13: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/13.jpg)
13
XML Attributes
Attributes are properties of the elementPairs of (name, value), within the elementValues are between quotation marks
<person isManager="true“ emplType=‘regular’>
<name>
….
</name>
</person>
Attributes
![Page 14: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/14.jpg)
14
Well Formed Documents
An XML document is well formed if obeys a set of rules1. Tags cannot be inferred; they must be explicit. All starting
tags must have corresponding ending tags. All ending tags must have corresponding starting tags
2. Empty tags need a Slash ( /) before the closing Greater Than (>) character: <person isManager=‘true’/>
3. All attribute values must be enclosed in either single or double quotation marks
4. Tags must nest correctly: <a><b></b></a>5. Tags are case sensitive and must match each other in
every implementation
![Page 15: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/15.jpg)
15
Namespaces in XML
Distinguish between elements and attributes from different XMLs
Qualified name = prefix:localPrefix is the NamespaceLocal identifies the particular element
1.xmlns:cmp=http://www.XML.org/company
xmlns:lb=http://www.XML.org/library2. <cmp:TITLE>Ms</cmp:TITLE>… <lb:TITLE>As You Like It</lb:TITLE>
Qualified name
![Page 16: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/16.jpg)
16
More in XML Documents
Empty elements: no children <ex x=“1”/> Comments <!-- No Comment --> Processing Instructions <? xml version=“1.0” ?> Entities <<..>.."..> Further readings
http://www.w3.org
![Page 17: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/17.jpg)
17
XML for Presentation
XMLdoc Presen-
tation
Voice XML
WML
HTML, PDF,PS
![Page 18: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/18.jpg)
18
XML for Communication
Appli-cation
A
Appli-cation
A
Appli-cation
1
Appli-cation
1
Appli-cation
B
Appli-cation
B
Appli-cation
2
Appli-cation
2
Transfor-mation
1
Transfor-mation
1
Transfor-mation
2
Transfor-mation
2
XML 1 XML 2
XML
![Page 19: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/19.jpg)
19
XML for Web Services
APPA
API
APPBA
PI
XML getAPI()
XML getAPI()
XML RPC (SOAP)
1
2
3
3
![Page 20: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/20.jpg)
20
Summary
We learned: XML is a vehicle for representing structured data XML allows you to create your own language (data format) An XML document contains start tags, end tags, elements and attributes,
CDATA Elements: parent, children, root element, document element
![Page 21: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/21.jpg)
21
Exercise (10 min.)
Write an XML document for the course you are attending: title: XML and Related Technologies description: basics of XML and related technologies instructor
Name: Marin Litoiu Affiliation: CAS
Participants Participant:
name: John Trevis job: software programmer
Participant Name: Big Boss Job: manager
…..……. View the document with IExplorer
![Page 22: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/22.jpg)
22
Quiz(1)
Which statement(s) is(are) false?:
1. XML makes data interchange easy
2. XML is a standard
3. XML is a meta-language
4. An well-formed XML document has nested tags and is a tree
5. An empty element has no attributes True or false?
1. XML is a protocol, like HTTP, IIOP and RMI
2. You can have rendering tags in XML documents
3. Attributes for Elements are like parts to whole
4. XML isolates the presentation from content
![Page 23: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/23.jpg)
23
Quiz(2)
XML is not a language and has not recognized tags. Rather, it is a meta-language that allows you to define your own language1. True2. False
Which of the following is not a rule for creating well-formed documents in XML?1. All start tags must have corresponding ending tags2. Empty tags need a Slash (/) before the closing Greater Than (>) character.3. All attribute values must be enclosed in brackets4. Tags must nest correctly5. Tags are case sensitive and must match each other in every implementation.
![Page 24: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/24.jpg)
24
Unit 2. DTDs
Learning Objectives What is DTD Why we need DTD How to write a DTD
![Page 25: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/25.jpg)
25
Document Type Definition(DTD)
DTD defines the grammar for XML docs Tag names How elements can be nested If the elements may, must appear How often the elements appear Attributes of the elements Default values for the attributes All valid values for the attributes
![Page 26: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/26.jpg)
26
Valid documents
The XML document contains information about its dtd
Exemple:<?xml version ="1.0" encoding= “US-ASCII” standalone="no"?><!DOCTYPE person SYSTEM “person.dtd">
A valid XML document follows the syntax defined in its dtd
An XML parser will check the validity of the XML document against its dtd
Any XML editor has an XML parser Eclipse has an XML Editor
![Page 27: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/27.jpg)
27
XML Documents and DTD
author.dtd
author1.xml author3.xmlauthor2.xml
author.class One editor
One parser
Many XMLs
……..
One DTD
![Page 28: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/28.jpg)
28
Simple person.dtd
<?xml version="1.0" encoding="UTF-8"?><!ELEMENT person (name, address)><!ATTLIST person isManager (true|false) 'false'><!ATTLIST person emplType CDATA #IMPLIED><!ELEMENT address (street,city*,state*, zip)><!ELEMENT name (title?,given, family)><!ELEMENT title (#PCDATA)><!ELEMENT family (#PCDATA)><!ELEMENT given (#PCDATA)><!ELEMENT street (#PCDATA)><!ELEMENT zip (#PCDATA)>
![Page 29: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/29.jpg)
29
Element definition
<!ELEMENT person (name, address)>
<!ELEMENT address (street, city*, state*, zip)>
<!ELEMENT name (title?, given, family)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT given (#PCDATA)>
…….
Element name Children Element declaration
Element Type
![Page 30: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/30.jpg)
30
Attributes in DTD
DTD<!ELEMENT person (name,address)><!ATTLIST person isManager (true|false) 'false'><!ATTLIST person emplType CDATA #IMPLIED>
XML<person isManager=“false”>
El. name
Attr. name
Attr type
Default value
![Page 31: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/31.jpg)
31
Empty Elements
No children, no start or end tag
DTD
<!ELEMENT apple EMPTY>
<!ATTLIST apple color CDATA #REQUIRED>XML
<apple color=“red”/>
![Page 32: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/32.jpg)
32
Attributes Types
CDATA “Eglinton East”NMTOKEN (name token): <name>ID: unique Id within a documentIDREF: a reference to an IDIDREFS: many IDREFENUMERATION: (a|b|c|d)ENTITY: reference to an external unparsed entityENTITIES: many ENTITY
![Page 33: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/33.jpg)
33
ID and IDREF
DTD: <!ATTLIST employee id #ID>
<!ATTLIST employee manager #IDREF>
XML: <employee name=“john” id=“056”>
<employee name=“bob” manager=“056”>
![Page 34: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/34.jpg)
34
Default values for attributes
#REQUIRED - a value MUST be provided #IMPLIED – optional value [#FIXED] “value”, if no value is provided, the “value” should be used
![Page 35: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/35.jpg)
35
Child Element Occurrences
“A man has zero or one wives, zero or more children and speaks one or more languages”<!ELEMENT man (child*, wife?, languages+)>
? zero or one times* zero or more times+ one or more times, sequence| or- choice
![Page 36: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/36.jpg)
36
Summary of Unit 2
We learned: DTD is the grammar for XML documents DTD defines: elements (parents and children), attributes, default and allowed
values DTDs are agreed upon by a community Valid XML documents obey the structure of DTD
![Page 37: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/37.jpg)
37
Exercise 1
Write an XML Document for person.dtd from slide 28 Validate the document with Internet Explorer make sure you specify the SYSTEM dtd
You can use an XML Editor For example, Eclipse has editors for XML, DTD and XML Schema.
![Page 38: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/38.jpg)
38
Quiz
Which statement(s) is(are) false1. DTD is a grammar for XML documents
2. IDREF is an attribute type and it means a reference to an attribute called “ID”
3. <!ELEMENT x (y+)> defines an element x with zero or more children elements y
4. <!ATTLIST y z (1|2) ‘2’> defines an attribute z for the element y. z can have 1 or 2 characteristics, preferably 2.
5. <!-- x=1--> is a valid comment
6. <!EMPTY bag> defines an empty element bag
![Page 39: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/39.jpg)
39
Unit 3. XML Schema
Learning Objectives Why we need XML Schema How to write an XML Schema When to use XML Schema
![Page 40: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/40.jpg)
40
XML Schema
DTD has few predefined types DTD syntax is different from XML syntax DTD cannot express certain constraints: “c occurs 3 to 5
times” XML Schema to the rescue
Describes and constrains the content of XML Defines simple data types and ways to derive new simple or
complex types Link: www.w3.org/XML/Schema Namespace: xmlns:xsd='http://www.w3.org/20001/XMLSchema'
![Page 41: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/41.jpg)
XML Schema structure
Schema element: the top level element ( as per XML definition) Element—defines the elements that will show up in your XML doc Simple type elements: simple elements derived from predefined elements in XML
schema Complex type elements: complex data types ( sequence, union..)
Example
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
<xsd:element .............</xsd:element>
<xsd:element..............</xsd:element>
…………………..
<xsd:simpleType.........</xsd:simpleType>
<complexType.............</xsd:complextype>
</xsd:schema>© Marin Litoiu, York University, Canada
![Page 42: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/42.jpg)
42
XML Schema uses XML Syntax
DTD
<!ELEMENT family (#PCDATA)>
<!ELEMENT given (#PCDATA)>
XML Schema
<xsd:element name="family“ type="xsd:string"/>
<xsd:element name="given" type=‘xsd:string’/>
XML attributes
??? XMLElements
![Page 43: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/43.jpg)
43
All Built in Types
![Page 44: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/44.jpg)
Simple types(1)
http://www.w3.org/TR/xmlschema-0/#ref18
Simple Type Examples (delimited by commas) Notes
string This is a string
normalizedString This is a string NL and CR are converted to spaces
token This is a string Trailing and leading spaces are removed
integer ...-1, 0, 1, ... integer is ·derived· from decimal by fixing the value of ·fractionDigits· to be 0and disallowing the trailing decimal point.
positiveInteger 1, 2, ...
negativeInteger ... -2, -1
nonNegativeInteger 0, 1, 2, ...
nonPositiveInteger ... -2, -1, 0
long-9223372036854775808, ... -1, 0, 1, ... 9223372036854775807
unsignedLong 0, 1, ... 18446744073709551615
int-2147483648, ... -1, 0, 1, ... 2147483647
int is ·derived· from long by setting the value of ·maxInclusive· to be 2147483647 and ·minInclusive· to be -2147483648.
unsignedInt 0, 1, ...4294967295
short -32768, ... -1, 0, 1, ... 32767
unsignedShort 0, 1, ... 65535
byte -128, ...-1, 0, 1, ... 127
unsignedByte 0, 1, ... 255
![Page 45: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/45.jpg)
Simple types(2)
http://www.w3.org/TR/xmlschema-0/#ref18
decimal -1.23, 0, 123.4, 1000.00
float-INF, -1E4, -0, 0, 12.78E-2, 12, INF, NaN
equivalent to single-precision 32-bit floating point, NaN is "not a number", INF-inifinite
double-INF, -1E4, -0, 0, 12.78E-2, 12, INF, NaN
equivalent to double-precision 64-bit floating point
boolean true, false, 1, 0
duration P1Y2M3DT10H30M12.3S1 year, 2 months, 3 days, 10 hours, 30 minutes, and 12.3 seconds
dateTime 1999-05-31T13:20:00.000-05:00May 31st 1999 at 1.20pm Eastern Standard Time which is 5 hours behind Co-Ordinated Universal Time
date 1999-05-31
time 13:20:00.000, 13:20:00.000-05:00
gYear 1999 1999, g stands for Gregorian calendar
gYearMonth 1999-02the month of February 1999, regardless of the number of days,
gMonth --05 May, regardless of year, day
gMonthDay --05-31 every May 31st
gDay ---31 the 31st day
![Page 46: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/46.jpg)
Examples
XML Schema
<element name=‘firstname' type=“string"/>
<element name='birthdate' type="date"/>
<element name='age' type="positiveInteger"/>
<element name=‘vacation' type=“gMonthYear"/>
XML Document
<firstname> John </firstname>
<birthdate > 2001-01-01 </birthdate>
<age> 9 </age>
<vacation> 2011-01</vacation>
© Marin Litoiu, York University, Canada
![Page 47: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/47.jpg)
Questions
How do I specify this structure of the XML elements?
<employeeName>
<family> John</family>
<given> Smith </given>
</employeeName> See next slide…
© Marin Litoiu, York University, Canada
![Page 48: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/48.jpg)
48
Complex Types in XML Schema: Sequence
Create once, use many times as a template High reusability, easy maintainability1. Types<xsd:complexType name="nameType"> <sequence> <xsd:element name="family" type="xsd:string"/> <xsd:element name="given" type="xsd:string"/> </sequence></xsd:complexType>---------------------------2. Elements<xsd:element name=“employeeName” type=“nameType” /><xsd:element name=“customerName” type=“nameType” />-----------------------------------
3. This how they will look in XML documents<employeeName> <family> John</family> <given> Smith </given> </employeeName>
<customerName> <family> Bill</family> <given> Gates </given> </customerName>
Is like “, “ in dtd
![Page 49: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/49.jpg)
Validating XMLs and XML schemas
Schema, in a file named name.xsd<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/Quiz"
xmlns:tns="http://www.example.org/Quiz"
elementFormDefault="qualified">
<complexType name="nameType">
<sequence>
<element name="family" type="string"/>
<element name="given" type="string"/>
</sequence>
</complexType>
<element name="employeeName" type="nameType" />
</schema>
XML file: references the file name.xsd
<?xml version="1.0" encoding="UTF-8"?>
<employeeName xmlns="http://www.example.org/Quiz"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.example.org/Quiz name.xsd ">
<family>Bill</family>
<given>Gates</given>
</employeeName> © Marin Litoiu, York University, Canada
![Page 50: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/50.jpg)
Quiz (10 min)
1. Write a valid xml document for this xml schema<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/Quiz"
xmlns:tns="http://www.example.org/Quiz"
elementFormDefault="qualified">
<complexType name="meetingType">
<sequence>
<element name="meetingName" type="string" />
<element name="meetingDay" type="gDay" />
<element name="meetingYear" type="gYear" />
<element name="meetingMonth" type="gMonth" />
<element name="meetingNoAttendees" type="integer" />
<element name="meetingCost" type="decimal" />
</sequence>
</complexType>
<element name="meeting" type="tns:meetingType"/>
</schema>
2. Write a simplified version of this XML schema (condense the types)
3. Write an XML document for the new schema
© Marin Litoiu, York University, Canada
![Page 51: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/51.jpg)
Complex Types: Choice
<xsd:complexType name="PurchaseOrderType">
<xsd:sequence>
<xsd:choice>
<xsd:element name=“USAddress“ type=“xsd:string”/>
<xsd:element name=“CAAddress" type=“xsd:string"/>
</xsd:choice>
<xsd:element name="items" type="Items"/>
</xsd:sequence>
…..<xsd:element name=‘computerOrder’ type=‘PurchaseOrderType’/>
<xsd:element name=‘computerOrder’ type=‘PurchaseOrderType’/>
Only one of those: USAddress or CAAddress will show up in an instance XML document
The address is followed by the items (items type is Items)
© Marin Litoiu, York University, Canada
![Page 52: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/52.jpg)
52
Anonymous Types
Anonymous type does not have name, it is a private child of the element it types
<xsd:element name="person“ type=“personType”> <xsd:element name="person"> <xsd:complexType> <xsd:sequence> <xsd:element name="name" type="nameType"/> <xsd:element name="address" type="addressType"/> </xsd:sequence> </xsd:complexType></xsd:element>
Anonymous
type
![Page 53: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/53.jpg)
53
Attributes
Attributes have name, value, type They are children of the element <xsd:element name="person"> <xsd:complexType> ………. <xsd:attribute name="id" type="xsd:ID"/> <xsd:attribute name="isManager" type="xsd:boolean"/> <xsd:attribute name="hiringDate" type="xsd:date"/> </xsd:complexType></xsd:element>
![Page 54: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/54.jpg)
54
Occurrence Constraints
Occurrence Constraints for Children ElementsminOccurs, maxOccurs
Ex: <xsd:element name=“languages” type=“positiveInteger”, minOccurs=“1”, maxOccurs=“100”/ >
Constraints for Attributes use, value
Ex: <xsd: attribute name="country" type=“xsd:string" use=“required" value="US"/>
![Page 55: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/55.jpg)
55
Derived Types-Pattern
“Phone number has an optional country code, an area code of tree digits, a hyphen, and 7 digits”
Use pattern<xsd:attribute name="phone">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:pattern value="(\d{2}-)?\d{3}-[0-9]{7}"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
![Page 56: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/56.jpg)
56
Derived Types-Interval
“age is an integer greater that 10, less than 121”<xsd:element name=“age">
<xsd:simpleType>
<xsd:restriction base="xsd:positiveInteger">
<xsd:maxExclusive value="121"/>
<xsd:minExclusive value=“10"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
![Page 57: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/57.jpg)
57
Derived Types- Enumeration
Enumerations are simple types<xsd:attribute name="emplType" default='regular'>
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value='regular'/>
<xsd:enumeration value='contractor'/>
<xsd:enumeration value='suplemental'/>
</xsd:restriction>
</xsd:simpleType>
![Page 58: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/58.jpg)
Derived types: Extension
<complexType name="Address">
<sequence>
<element name="name" type="string"/>
<element name="street" type="string"/>
<element name="city" type="string"/>
</sequence>
</complexType>
<complexType name="USAddress">
<complexContent>
<extension base="ipo:Address">
<sequence>
<element name="state" type="ipo:USState"/>
<element name="zip" type="positiveInteger"/>
</sequence>
</extension>
</complexContent>
</complexType>
http://www.w3.org/TR/xmlschema-0/#po.xsd
![Page 59: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/59.jpg)
59
DTD or XML Schema
For reach type documents, with many types and constrains, use XML schemas
Use DTD when Want a compact representation Not interested in semantic of the grammar, just in structure
![Page 60: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/60.jpg)
60
Summary
We learned: XML Schema is a replacement for DTD
Has a syntax similar to XML
Allows the user to Specialize by extension and restriction basic simple types Define his/her own complex types
![Page 61: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/61.jpg)
Exercise (10 min).
1. For the po.xsd schema from http://www.w3.org/TR/xmlschema-0/#po.xsd, write a sample xml document ( should be different from the one on web site)
http://www.w3.org/TR/xmlschema-0/#po.xsd
![Page 62: ITEC 4020A:Internet Client Server Systems Professor: Marin Litoiu Lecture 9&10 Web Service-XML © Marin Litoiu, York University, Canada.](https://reader035.fdocuments.in/reader035/viewer/2022062309/56649f315503460f94c4bee9/html5/thumbnails/62.jpg)
62
Quiz
True of false?
1. XML schemas are more compact that DTDs
2. To define complex types, one should use <complexType> tag
3. Declaration <xsd:attribute name=“y” type=“z”/> is incorrect because is does not specify the name of the element y belongs to
4. “restriction” is a specialization mechanism in XML schema that constrains a “base” type
5. The user can only create complex types but cannot create simple types
6. “enumeration” is a simple type