Brief Overview of XML Brief Overview of XML: Mike P. Papazoglou & Mikep@uvt - NL
Brief Overview of XML Brief Overview of XML: Mike P. Papazoglou & Mikep@uvt - NL
Chapter 3
Brief Overview of XML
ology
echno
cipless & Te
Web Servvices:
Princ
Michael P. Papazoglou, Web Services, 1st Edition, © Pearson Education Limited 2008
Slide 3.2
Topics
Michael P. Papazoglou, Web Services, 1st Edition, © Pearson Education Limited 2008
Slide 3.3
Markup
Example:
<centre on> This is a <italics on> very serious <italics
off> matter
matter.<centre
<centre off>
“Tags” are easily understandable by both the human reader and the machine.
Michael P. Papazoglou, Web Services, 1st Edition, © Pearson Education Limited 2008
Slide 3.4
XML
Michael P. Papazoglou, Web Services, 1st Edition, © Pearson Education Limited 2008
Slide 3.5
<BOOK>
<TITLE>
TITLE
Web Services: Principles and
Technology
</TITLE>
<AUTHOR>
Mike P. Papazoglou
p g
</AUTHOR>
This document has XML tags.
<DATE> 2007 </DATE>
A human and a computer can now easily
<PUBLISHER>
extract the publisher data.
Prentice Hall
</PUBLISHER>
</BOOK>
Michael P. Papazoglou, Web Services, 1st Edition, © Pearson Education Limited 2008
Slide 3.6
XML structure
• Document type: XML documents are regarded as having types.
– XML’s constituent parts and their structure formally define the type of a
document.
document
• An XML document is composed of named containers and their
contained data values.
– containers are represented as declarations, elements, and attributes.
• An XML document is also known as an instance or XML document
instance to signify that it represents one possible set of data for a
particular markup language.
<?xml version="1.0"
version 1.0 encoding
encoding="UTF-8"?>
UTF 8 ?>
<BillingInformation>
<Name> Right Plastic Products </Name>
<BillingDate> 2002-09-15 </BillingDate>
Example
l off an XML d
document iinstance. <Address>
<Street> 158 Edward st. </Street>
<City> Brisbane </City>
<State> QLD </State>
<PostalCode> 4000 </PostalCode>
/
</Address>
</BillingInformation>
Michael P. Papazoglou, Web Services, 1st Edition, © Pearson Education Limited 2008
Slide 3.7
Michael P. Papazoglou, Web Services, 1st Edition, © Pearson Education Limited 2008
Slide 3.8
XML: Elements
• Elements are fundamental units of content comprising element name and
element content.
– An element is a sequence
q of characters that begins
g with a start tag
g and ends with an
end tag and includes everything in between.
<chapter number="1">
Text for Chapter 1
</chapter>
• What is content?
The characters in between the tags (rendered in green in this presentation)
constitute the content.
content
XML: Attributes
Michael P. Papazoglou, Web Services, 1st Edition, © Pearson Education Limited 2008
Slide 3.10
XML Namespaces
• Namespaces in XML provide a facility for associating the elements
and/or attributes in all or part of a document with a particular schema
and avoiding name clashes
clashes.
• Namespace declarations have a scope.
– A namespace
p declaration is in scope
p for the element on which it is
declared and of that element’s children.
• The namespace name and the local name of the element together
f
form a globally
l b ll unique
i name kknown as a qualified
lifi d name.
<?xml version=”1.0” encoding=”UTF-8”?>
<BillingInformation customer-type=”manufacturer”
xmlns="http://www.plastics_supply.com/BillInfo">
<Name> Right Plastic Products </Name>
<Address xmlns="http://www.plastics_supply.com/Addr">
<Street> 158 Edward st. </Street>
<City> Brisbane </City>
<State> QLD </State>
<PostalCode> 4000 </PostalCode>
</Address>
Uniform resource identifier ((URI).
)
<Billi D t > 2002-09-15
<BillingDate> 2002 09 15 </BillingDate>
</Billi D t >
</BillingInformation>
Michael P. Papazoglou, Web Services, 1st Edition, © Pearson Education Limited 2008
Slide 3.11
XML: structure
Linear sequence
q
• An XML document must <book>
have a root tag. <chapter n=“1”> Title 1 </chapter>
<section n=“1.1”> Section 1.1 </section>
<paragraph> …. <paragraph>
<section n=“1.2”> Section 1.2 </section>
• An XML document is an <chapter n=“2”> Title 2 </chapter>
<section n=“2.1”> Section 2.1 </section>
information unit that can be < paragraph > …. < paragraph >
</book>
seen in two ways:
– As a linear sequence of
characters that contain Tree
characters data and markup. Book
– As an abstract data structure Chapter Chapter
p
that is a tree of nodes.
Section Section Section
Para Para
Michael P. Papazoglou, Web Services, 1st Edition, © Pearson Education Limited 2008
Slide 3.12
XML Schema
Michael P. Papazoglou, Web Services, 1st Edition, © Pearson Education Limited 2008
Slide 3.13
Michael P. Papazoglou, Web Services, 1st Edition, © Pearson Education Limited 2008
Slide 3.14
Schema Components
• Elements and their content model
<element name="item">
<annotation>
<documentation>One item of a purchase order with its
details</documentation>
</annotation>
<complexType>
<sequence>
<choice>
<element name="productName" type="string"/>
<element name="productName" type="string"/>
</choice>
<element name="quantity">
<simpleType>
<restriction base="positiveInteger">
<maxExclusive value="100"/>
</restriction>
</simpleType>
</element>
<element name="price" type="decimal">
<annotation>
<documentation>Needs to be specified in
US$</documentation>
</annotation>
</element>
<element ref="ipo:comment" minOccurs="0" maxOccurs="5"/>
<element name="shipDate" type="date" minOccurs="0"/>
</sequence>
<attribute name="partNum" type="ipo:Sku"/>
</complexType>
</element>
Michael P. Papazoglou, Web Services, 1st Edition, © Pearson Education Limited 2008
Slide 3.15
<xs:attribute name="name"
name name type xs:NCName />
type="xs:NCName"/>
<xs:attribute name="mixed" type="xs:boolean" use="optional" default="false"/>
<xs:attribute name="abstract" type="xs:boolean" use="optional" default="false"/>
<xs:attribute name="final" type="xs:derivationSet"/>
<xs:attribute name="block" type="xs:derivationSet"/>
Michael P. Papazoglou, Web Services, 1st Edition, © Pearson Education Limited 2008
Slide 3.16
• Complex Types
<xsd:complexType name="PersonType">
<xsd:sequence>
d
<xsd:element name="First" type="xsd:string"/>
<xsd:element name="Last" type="xsd:string"/>
<xsd:element name="Title" type="xsd:string“
yp g
minOccurs="0"/>
<xsd:element name="PhoneExt" type="xsd:int"/>
<xsd:element ref="EMail"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="Person" type="PersonType"/>
<xsd:element name="VIP“
substitutionGroup="Person">
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="PersonType">
base= PersonType >
<xsd:attribute name="IQ" type="xsd:int"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
Michael P. Papazoglou, Web Services, 1st Edition, © Pearson Education Limited 2008
Slide 3.17
Topics
Michael P. Papazoglou, Web Services, 1st Edition, © Pearson Education Limited 2008
Slide 3.18
<xsd:schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:PO="http://www.plastics_supply.com/PurchaseOrder"
targetNamespace="http://www.plastics_supply.com/PurchaseOrder">
<xsd:complexType name="Address">
<xsd:sequence>
<xsd:element name="Number" type="xsd:decimal"/>
<xsd:element name="Street" type="xsd:string"/>
/
<xsd:element name="City" type="xsd:string" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="AustralianAddress">
<xsd:complexContent>
<xsd:extension base="PO:Address">
<xsd:sequence>
<xsd:element name="State" type="xsd:string"/>
<xsd:element name="PostalCode" type="xsd:decimal"/>
<xsd:element name="Country" type="xsd:string"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:schema>
/
Michael P. Papazoglou, Web Services, 1st Edition, © Pearson Education Limited 2008
Slide 3.19
<!-- Uses the data type declarations from Listing on page 17 -->
<xsd:complexType name="AustralianPostalAddress">
<xsd:complexContent>
<xsd:restriction base="PO:AustralianAddress">
<xsd:sequence>
<xsd:element name="Number" type="xsd:decimal"/>
/
<xsd:element name="Street" type="xsd:string"/>
<xsd:element name="City" type="xsd:string" minOccurs="0" maxOccurs="0"/>
<xsd:element name="State" type="xsd:string"/>
< d l
<xsd:elementt name="PostalCode"
"P t lC d " type="xsd:decimal"/>
t " d d i l"/>
<xsd:element name="Country" type="xsd:string"/>
</xsd:sequence>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
Michael P. Papazoglou, Web Services, 1st Edition, © Pearson Education Limited 2008
Slide 3.20
<!-- Uses the data type declarations from Listing on page 17 -->
<xsd:complexType name="PurchaseOrder"> Variant of the PurchaseOrder
<xsd:sequence>
type that uses the base type
<xsd:element name="Name" minOccurs="1" maxOccurs="1">
Address for its billingAddress
<xsd:simpleType>
<xsd:restriction base="xsd:string"/> and shippingAddress elements.
</xsd:simpleType>
</ d l
</xsd:element>
t>
<xsd:element name="shippingAddress" type="PO:Address" minOccurs= "1"
maxOccurs="1"/>
<xsd:element name="billingAddress" type="PO:Address" minOccurs= "1"
maxOccurs="1"/>
<xsd:choice minOccurs="1" maxOccurs="1">
<xsd:element name="BillingDate" type="xsd:date"/>
<xsd:element name="ShippingDate" type="xsd:date"/>
</xsd:choice>
</xsd:sequence>
</xsd:complexType
Michael P. Papazoglou, Web Services, 1st Edition, © Pearson Education Limited 2008
Slide 3.21
Topics
Michael P. Papazoglou, Web Services, 1st Edition, © Pearson Education Limited 2008
Slide 3.23
Michael P. Papazoglou, Web Services, 1st Edition, © Pearson Education Limited 2008
Slide 3.25
<ShippingInformation>
<Name> Right Plastic Products Co. </Name>
<Address>
<Street> 459 Wickham st. </Street>
<City> Fortitude Valley </City>
<State> QLD </State>
<PostalCode> 4006 </PostalCode> XPath Query#1: /PurchaseOrder/Order[2]/child::*
</Address>
<ShippingDate> 2002-09-22 </ShippingDate>
</ShippingInformation> Resulting Node Set#1:
=====================
<BillingInformation> <Product Name="Adjustable Worktable" Price="3000.00"
<Name> Rightg Plastic Products Inc. </Name> Quantity="1"/>
Quantity= 1 />
<Address>
<Street> 158 Edward st. </Street>
<City> Brisbane </City>
<State> QLD </State>
<PostalCode> 4000 </PostalCode>
</Address>
<BillingDate> 2002-09-15 </BillingDate>
</BillingInformation>
Michael P. Papazoglou, Web Services, 1st Edition, © Pearson Education Limited 2008
Slide 3.26
XML
26
Michael P. Papazoglou, Web Services, 1st Edition, © Pearson Education Limited 2008
Slide 3.27
Transformation service
<PurchaseOrder>
<Name> Plastic Products </Name>
<billingAddress>
<Number> 158 </Number>
<Street> Edward st. </Street> Target
<PostalCode> QLD 4000 </PostalCode> XML
<Country> Australia </country> application
pp
</billi Add
</billingAddress>>
<PurchaseOrder>
Michael P. Papazoglou, Web Services, 1st Edition, © Pearson Education Limited 2008