Pal gov.tutorial3.session2.xml ns and schema

jarrar02 391 views 51 slides Jun 01, 2012
Slide 1
Slide 1 of 51
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51

About This Presentation

No description available for this slideshow.


Slide Content

1PalGov© 2011
ةينيطسلفلا ةينورتكللإا ةموكحلا ةيميداكأ
The PalestinianeGovernmentAcademy
www.egovacademy.ps
Tutorial III:
Process Integration and Service Oriented Architectures
Session 2
Overview XML NS and Schema
Prepared By
Mohammed Aldasht
Reviewed by
Prof. Marco Ronchettiand Prof. Paolo Bouquet, Trento University, Italy

2PalGov© 2011
About
This tutorial is part of the PalGovproject, funded by the TEMPUS IV program of the
Commission of the European Communities, grant agreement 511159-TEMPUS-1-
2010-1-PS-TEMPUS-JPHES. The project website: www.egovacademy.ps
University of Trento, Italy
University of Namur, Belgium
VrijeUniversiteitBrussel, Belgium
TrueTrust, UK
Birzeit University, Palestine
(Coordinator)
Palestine Polytechnic University, Palestine
Palestine Technical University, Palestine
Université de Savoie, France
Ministry of Local Government, Palestine
Ministry of Telecom and IT, Palestine
Ministry of Interior, Palestine
Project Consortium:
Coordinator:
Dr. Mustafa Jarrar
Birzeit University, P.O.Box14-Birzeit, Palestine
Telfax:+972 2 2982935 [email protected]

3PalGov© 2011
©Copyright Notes
Everyone is encouraged to usethis material, or part of it, but should properly
cite the project(logo and website), and the author of that part.
No part of this tutorial may be reproduced or modified in any form or by any
means, without prior written permissionfrom the project, who have the full
copyrights on the material.
Attribution-NonCommercial-ShareAlike
CC-BY-NC-SA
This license lets others remix, tweak, and build upon your work non-
commercially, as long as they credit you and license their new creations
under the identical terms.

Tutorial Map
Title T Name
Session0: Syllabus and overview 0Aldasht
Sesson1: Introduction to SOA 2Aldasht
Session2: XML namespaces & XML schema 2Aldasht
Session 3: Xpath& Xquery 4Romi
Session4: REST web services 3M. Melhem
Session5: Lab2: Practice on REST 3M. Melhem
Session 6: SOAP 2Aldasht
Session 7: WSDL 3Aldasht
Session8: Lab 3: WSDL practice 3Aldasht
Session9: ESB 4Aldasht
Session10: Lab4: Practice on ESB 4Aldasht
Session11: integration patterns 4M.Melhem
Session12: Lab5: integration patterns 4M. Melhem
Session13: BPEL 3Aldasht
Session14: Lab6: Practice on BPEL 3Aldasht
Session15: UDDI 2Aldasht
Intended Learning Objectives
A: Knowledge and Understanding
3a1: Demonstrate knowledge of the fundamentals of middleware.
3a2: Describe the concept behind web service protocols.
3a3: Explain the concept of service oriented architecture.
3a4: Explain the concept of enterprise service bus.
3a5: Understanding WSDL service interfaces in UDDI.
B: Intellectual Skills
3b1: Design, develop, and deploy applications based on Service
Oriented Architecture (SOA).
3b2: use Business Process Execution Language (BPEL).
3b3: using WSDL to describe web services.
C: Professional and Practical Skills
3c1: setup, Invoke, and deploy web services using integrated
development environment.
3c2: construct and use REST and SOAP messages for web
services communication.
D: General and Transferable Skills
d1: Working with team.
d2: Presenting and defending ideas.
d3: Use of creativity and innovation in problem solving.
d4:Develop communication skills and logical reasoning abilities.

Session Outlines
XML Overview
XML document and Grammars
XML information set
XML Namespaces
XML Schema
5e-Government Lifelong Learning

Overview
•XMLisamarkuplanguage,likeHTML,consistsofmarkup
andtext.
•Markupiscomposedofindividualtags.
•BothHTMLandXMLarelanguagesforexchangingdata,but
thereisadifferencebetweenthem.
•SeenextslideforandinitialXMLexample.
6e-Government Lifelong Learning

Valid and well-formed XML document
•ValidXMLdocumentisonethatcomplywiththeconstraints
expressedthroughagivengrammar.
•Awell-formedXMLdocumentisonethatcomplywithXML
syntaxexpressedintheXMLstandard.
–Butnotassociatedwithadistinctgrammar.
7e-Government Lifelong Learning

XML grammars
•Specifiedbytwodominantconcepts:
–XMLschemaandDocumentTypeDefinitions(DTDs)
•XMLschemaispowerfultoexpressstructuralXMLdocument
constraintsthanDTDs.
•XMLdocumentcomplyingwithaDTDoraschemaiscalled
andXMLinstanceorinstancedocument.
•Seenextslide,fortherelationshipbetweenXMLdocument
grammarandXMLinstancesresultingfromapplyingthe
grammar.
8e-Government Lifelong Learning

XML document grammar and valid XML instances, [2]
9e-Government Lifelong Learning
XML Schema, DTD
(XML Document Grammar)
XML Instance,
Instance Document
XML Instance,
Instance Document
XML Instance,
Instance Document
XML Instance,
Instance DocumentValid
Documents

XML processor
•Applicationsareinterestedinthe
structuralinformationandthe
XMLinstance,whenXMLisused
toexchangedatabetweenthem.
•XMLprocessor,e.g.SOAPserver,
mustvalidatetheXMLdocuments
againsttheXMLgrammarand
passtheXMLinstancestructure
andpayloadtotheapplication,e.g.
SOAPmessage.
XML Application
XML Processor
XML Instance
XML Instance
XML Instance
XML Schema,
DTD
A validating XML processor,[2]
10e-Government Lifelong Learning

Session Outlines
XML Overview
XML document and Grammars
XML information set
XML Namespaces
XML Schema
11e-Government Lifelong Learning

XML information set
•XMLinfoset,providesasetofabstractdatadefinitionsto
representtheinformationinawell-formedXMLdocument.
–Eachwell-formedXMLdocumenthasanassociatedinfoset.
•Theinformationsetconsistsofinformationitems.
–EachitemdescribesanXMLdocumentpartthroughasetofnamed
properties
12e-Government Lifelong Learning

Information item types of an XML information set, [2]
document
document
type
declaration
element
Character
data
attribute
Property
children
Property
attribute
13e-Government Lifelong Learning

Information item types of an XML information set
•document, consists at least of one mandatory root element,
and:
–XML version info (optional) & encoding info for the document. These are
called XML declaration.
–Document type declaration: contains markup declarations provide the
grammar.
–These together is called prolog.
14e-Government Lifelong Learning

Information item types of an XML information set,
cont.
•element: identified by a name and has a set of associated
attributes.
•attribute: consists of a name and an associated value.
•character data: is an information item comprises the
payload of an XML document.
•comment: elementand documentinformation items may
contain comments.
15e-Government Lifelong Learning

Information item types examples [2]
•Comment info item “may span multiple lines”:
–<!–This is a comment -->
•Element info item:
–element may have no content e.g.: <address/> or
<address></address>
<address>
<name>MrAhmad Ahmad</name>
<street>11 AlqudsStreet</street>
<city>Ramallah</city>
<postal-code>100</postal-code>
<country>Palestine</country>
</address>
16e-Government Lifelong Learning

Information item types examples [2]
•Anattributeisspecifiedinthestarttagofanelementand
consistsofaname-valuepair.
–ThisexamplelinksanattributenamedtargetAddresswiththe
“PS”totheaddresselements:
17e-Government Lifelong Learning
<address targetAddress=“PS”>
<name>MrAhmad Ahmad</name>
<street>11 AlqudsStreet</street>
<city>Ramallah</city>
<postal-code>100</postal-code>
<country>Palestine</country>
</address>

Information item types examples [2]
•Documentinfoitem:looktothefollowingprolog:
<?xmlversion=“1.0”encoding=UTF-16”?>
<!DOCTYPEaddress[<!–DTDsgohere-->]>
<address><!–XMLinstancesgohere--></address>
•DocumenttypedeclarationidentifiedbykeywordDOCTYPE
mustbeidenticaltothecorrespondingrootelement
18e-Government Lifelong Learning

Information item types examples
•elementcontent:ifdeclaredtobecharacterdata,thisis
indicatedbytheterm#PCDATA.“ParsedCharacterData”
–Thus,avaliddeclarationwouldbe:
<?xmlversion=“1.0”encoding=UTF-16”?>
<! DOCTYPE address [<!ELEMENT address
(#PCDATA)>]>
•InanXMLinstancetheaddresselementcouldappearas
follows:
19e-Government Lifelong Learning
<address>
MrAhmad Ahmad
11 AlqudsStreet
Ramallah
100
Palestine
</address>

Element content and mixed content
•We can combine elements and build nested element
declarations.
•DTD syntax provides 5 symbols used to describe manners of
combination.
•Assume e1, e2and e3to be elements:
–e1? : ?means none or one element e1.
–e1* : *means none, one or more element e1.
–e1+ : +means one or more than one element e1.
–e1, e2, e3: ,means list of element are chained.
–e1 | e2: means e1or e2can be chosen but not both.
20e-Government Lifelong Learning

addresselement can have this structure, [2]
21e-Government Lifelong Learning
Source, [2]
address
street city Postal-code
titleFirst-name
11
n
1
Mandatory
Optional
Containment
Relationship
name country
11
Last-name
10..1

A DTD describing the addressstructure, [2]
22e-Government Lifelong Learning
<?xml version=“1.0” encoding=“UTF-16”?>
<!DOCTYPE address [
<!ELEMENT address (name+, street, city, postal -code,
country)>
<!ELEMENT name (title?, first -name, last-name)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT first-name (#PCDATA)>
<!ELEMENT last-name (#PCDATA)>
<!ELEMENT street (#PCDATA)>
<!ELEMENT city (#PCDATA)>
<!ELEMENT postal-code(#PCDATA)>
<!ELEMENT country(#PCDATA)>
]>

An instance document could be as shown here
23e-Government Lifelong Learning
<address>
<name>
<title selectTitle=“Mr”/>
<first-name>Ahmad M.</first -name>
<last-name>Ahmad</last-name>
</name>
<street>11 AlqudsStreet</street>
<city>Ramallah</city>
<postal-code>100</postal-code>
<country>Palestine</country>
</address>

A valid address XML instance
24e-Government Lifelong Learning
<address targetAddress=“PS”>
<name>
<title selectTitle=“Mr”/>
<first-name>Ahmad M.</first -name>
<last-name>Ahmad</last-name>
</name>
<street>11 AlqudsStreet</street>
<city>Ramallah</city>
<postal-code>100</postal-code>
<country>Palestine</country>
</address>

Session Outlines
XML Overview
XML document and Grammars
XML information set
XML Namespaces
XML Schema
25e-Government Lifelong Learning

XML Namespaces
•XMLprocessormustbeabletodifferentiateourXML
addressinstancesfromsomeoneelse’saddress
instances.
–Identificationusingelementtypenamesisnotsufficient.
•Someglobalnamingmechanismisrequired.
•XMLnamespacesensurethatXMLdefinitionsare
unique.
•UsingXMLnamespaces,XMLelementscanbe
distinguished,eveniftheyhaveidenticalnames.

XML Namespaces concept
•An XML namespace comprises a collection of element
type names & attribute names.
•An XML namespace, is identified by a URI reference.
•The collection of element type names & attribute names,
belonging to the same namespace are identified by the
namespace URI reference.
•See next slide for namespaces example!

Identical markup belonging to different namespaces
<member>
<member-id>
<member-since>
<name>
<address>
<employee-id>
<dept-number>
<name>
<address>
<order>
<order-number>
<order-date>
<name>
<address>
http://companyx.com/ns/employees
http://companyx.com/ns/orders
http://clubx.com/ns/members
Source, [2], with modifications

Qualified names
•Anamefromanamespaceappearsinadocumentasa
qualifiedname(Qname).
•AQnameconsistsofaprefixandalocalpart.
•e.g.cXistheprefixandaddressisthelocalpart:
cX:address
•Prefixselectsthenamespaceandlocalparttakecare
ofthenamingwithinthescopeofthenamespace.

Declaring XML namespaces
•Donethroughthereservednamespaceattributexmlns.
•Also,canbedonethroughxmlns:followedbyaname
withoutcolons.
•ThevalueofthenamespaceattributeistheURIreference.
•Linkinganamespacetoaprefix,e.g.:
<addressxmlns:cX=“http://companyx.com/ns/employees”>
–cXistheprefixforallqualifiednamesbelongingtothenamespace
•Usingadefaultnamespace,e.g.:
<addressxmlns=“http://companyx.com/ns/employees”>
–Allsubordinateelementsareinthesamedefaultnamespace,unlessa
subordinateelementoverwritesthedefaultnamespace.

Declaring a namespace for the address document,
using prefix namespace attribute
<cX:addressxmlns:cX=“http://companyx.com/ns/employees”
targetAddress=“PS”>
<cX:name>
<cX:titleselectTitle=“Mr”/>
<cX:first-name>Ahmad M.</cX:first-name>
<cX:last-name>Ahmad</cX:last-name>
</cX:name>
<cX:street>11 AlqudsStreet</cX:street>
<cX:city>Ramallah</cX:city>
<cX:postal-code>100</cX:postal-code>
<cX:country>Palestine</cX:country>
</cX:address>

Using a default namespace name declaration
<address xmlns=“http://companyx.com/ns/employees”
targetAddress=“PS”>
<name>
<title selectTitle=“Mr”/>
<first-name>Ahmad M.</first -name>
<last-name>Ahmad</last-name>
</name>
<street>11 AlqudsStreet</street>
<city>Ramallah</city>
<postal-code>100</postal-code>
<country>Palestine</country>
</address>

An example for an entry of the phone book
maintained by the company
<phonebook xmlns=“http://companyx.com/ns/phonebook”
<location>Company X Office</location>
<roomNumber>03.02</roomNumber>
<!–-Extension -->
<officePhone>*2911111</officePhone>
</phoneBook>

XML namespaces and attributes
•Defaultnamespacesarenotappliedtoattributesthatdonot
haveaprefix.
•ThefollowingexampleisavalidXMLinstance.
–AlthoughthelocalpartofthelocationelementattributeisIdentical.
<!--Declare a namespace prefix
<phoneOwnerxmlns:phone=“http://companyx.com/ns/phonebook”
<!--for illustrative purposes, not a good XML practice. -->
<phonebook xmlns=“http://companyx.com/ns/phonebook”
<location department=“HR” phone:department=“HR”>
Company X Office</location>
</phoneBook>
</phoneOwner>

Session Outlines
XML Overview
XML document and Grammars
XML information set
XML Namespaces
XML Schema
35e-Government Lifelong Learning

XML schema
•IfwewanttoinserttheroomNumberelementtothephone
bookasfollows:
–AroomNumbervaluemuststartwith2digitsdescribingthebuilding
floor,followedbyadot.
–Then,a2moredigitstorepresenttheroomnumberonthatfloor.
•NowaytospecifythispatternthroughaDTD.
•XMLschemaallowsustoexpresssuchaconstraints.
•VariousdatatypescanbedefinedwithXMLschemaandnew
datatypescanbederivedfromexistingones.

An initial XML schema example
<simpleTypename=“roomNumberType”>
<restriction base=“string”>
<pattern value=“[0-9]{2}\.[0-9]{2}”/>
</restriction>
</simpleType>
<elementname=“roomNumber” type=“roomNumberType”/>
Typedefinition
Element declaration
The element named
roomNumberis of type
roomNumberType
It is a simple type
based on XML schema
built-in type “string”
restricting the string to
a distinct string pattern
(the string pattern is
also called a facet)
Source, [2]

The structure of an XML schema definition
•AnXMLSchemaDefinition(XSD)isitselfanXMLinstance.
–AnadvantageoftheXMLschema.
•Thetopelementofthexsdisnameschema.
•TheXMLnamespaceforaschemadefinitionis
http://www.w3.org/2001/XMLSchema,linkedto
prefixxsd.Startaschemadefinitionas:
<xsd:schema
xmlns:xsd=“http://www.w3.org/2001/XMLSchema”>
....</xsd:schema>

Some of subordinate element types of schema
element.
•element:declaresanelementusedinanXMLinstance.
•attribute:declaresanattributeusedinanXMLinstance.
•simpleType:thiselementdefinesasimpletype,whichisan
XMLschemabuilt-intype.
•complexType:thisdefinitiontypicallycontainsXML
elementsandcarryattributes,alldeclaredwithinthetype
definition.

XML schema containment structure of a simple
type definition
•Onlyoneexclusiveelementmustbecontainedinthesuperior
element.
simpleType
restriction list union
“an approppriate
facet”
“an approppriate
facet”
“an approppriate
facet”
“an approppriate
facet”
“an approppriate
facet”
“an approppriate
facet”
0..1
0..1
0..1
n
nn
6 applicable facets2 applicable facets12 applicable facets
Mandatory
Optional
Exclusive
Containment
Relationship
Source, [2]

Attribute links between simple type XML schema
elements
Source, [2]
restriction
list
union
XML Schema
Built-in type
“a simple
type”
base
itemType
base
itemType
memberTypesmemberTypes
Linked-to
Relationship

A type definition for the title element
Global elementsmay appear at the top level of an XML
instance:
<xsd: simpleTypename=“titleTypeUK”>
<xsd:restriction base=“xsd:string”>
<xsd:enumeration value=“Miss”/>
<xsd:enumeration value=“Mr”/>
<xsd:enumeration value=“Mrs”/>
<xsd:enumeration value=“Ms”/>
</xsd:restriction>
</xsd:simpleType>
<xsd:schemaxmlns:xsd=“http://www.w3.org/2001/XMLSchema”>
...
<!–-“titleTypeUK”definitiongoeshere-->
<xsd:elementname=“title”type=“tns:titleTypeUK”/>
</xsd:schema>

A type definition for the first-name element
minLengthand maxLength
<xsd: simpleTypename=“firstNameType”>
<xsd:restriction base=“xsd:string”>
<xsd:patternvalue=“[A-Z][a-z]*”/>
</xsd:restriction>
</xsd:simpleType>
<xsd: simpleTypename=“firstNameType”>
<xsd:restriction base=“xsd:string”>
<xsd:patternvalue=“[A-Z][a-z]*”/>
<xsd:minLengthvalue=“2”/>
<xsd:maxLengthvalue=“20”/>
</xsd:restriction>
</xsd:simpleType>

XML schema containment structure of a complex
type definition
•Onlyoneexclusiveelementmustbecontainedinthesuperior
element.Andanarbitrarynumberofattribute.
Source, [2]
complexType
sequence choice all
element
element
0..10..1
n
n nn
Mandatory
Optional
Exclusive
Containment
Relationship
Attribute/
Attribute
group
group
0..10..1
element
element
element
element
element
element
n

Complex type definitions
•ThefollowingXMLschemapresentsagroupnamed
nameGroupthatisreferredtowithinacomplextype
definition,[2].
<!--this is the named group definition.
<xsd:groupname=“nameGroup”>
<xsd:sequence>
<!--Here is the type definition of a name -->
</xsd:sequence>
</xsd:group>
<!--Here the named group if referred to within a complex type. -->
<xsd:complexType name=“addressType”>
<xsd:sequence>
<!--Here is the reference to the above defined group -->
<xsd:groupref=“nameGroup”/>
. . .
</xsd:sequence>
</xsd:complexType>

XML schema containment structure for deriving
types by extension
•simpleContentandcomplexContentelementsmustbe
superiortoeitherrestrictionorextensionelements.
Source, [2]
complexType
Simple
Content
Complex
Content
Mandatory
Exclusive
Containment
Relationship
0..10..1
restriction extension restriction extension
0..1 0..1 0..1 0..1

Linking XML schemas to XML instances
•schemaLocationattributecontainsvaluepairs:
–Thefirstvalueisanamespace.
–Thesecond,providesalinktotheschemausedforvalidatingelementsand
attributescontainedinthisnamespace.

Linking schemas to instances
•Tolinktheaddressdocumentinstancetotheaddressschema
viatheschemaLocationattribute,weneedtoaddthis
attributetotheinstancedocument.
Example
<cX:address
xmlns:cX=“http://companyx.com/ns/employees”
xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance
xsi:schemaLocation=“http://companyx.com/ns/employees
http://localhost/address.xsd”>
...
<!--thefirstURIdefinesthenamespaceforelementsand -->
<!--attributesinthisdocument,forwhichthesecondURI-->
<!--pointstotheschemalocationoftheschemathat -->
<!--canbeusedtovalidatetheseelementsandattributes -->
</cX:address>

Summary
Duringthissessionwehaveexplainedwithexamplesthe
following:
1.XMLnamespaces
2.XMLschema
NextsessionwillcoverXpathandXquery.

References
1.Bray T, Paoli J, Sperberg-McQueen C M, MalerE. Extensible Markup Language
(XML) 1.0 (Second Edition), W3C Recommendation 6 October 2000,
http://www.w3.org/TR/REC-xml, 2000.
2.Olaf Zimmermann, Mark Tomlinson, Stefan Peuser, “Perspectives on Web services-
Applying SOAP, WSDL and UDDI to real-world projects, 2nd edition, Springer, 2005.

Thanks
Mohammed Aldasht
Tags