0% found this document useful (0 votes)
12 views74 pages

UNIT-1 SOA - 21CS913 - Digital Notes

Uploaded by

dhanushkethineni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views74 pages

UNIT-1 SOA - 21CS913 - Digital Notes

Uploaded by

dhanushkethineni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 74

1

2
21CS913
SERVICE OREIENTED ARCHITECTURE

Department: CSE
Batch/Year: 2021-25 / IV
Created by:
Dr.G.Indra
Mr.V.M.Jemin

Date: 15.07.2024

3
1. CONTENTS

S.N Page
Contents
o No.

1 Course Objectives 5

2 Pre-Requisites 6

3 Syllabus 7

4 Course outcomes 8

5 CO- PO/PSO Mapping 9

7 Unit – I

Lecture Plan 11

Activity based learning 12

Lecture notes 13

Assignments 47

Part A Q & A 48

Part B Qs 50

Supportive online Certification courses 51

Real time Applications in day to day life and to


52
Industry

Contents beyond the Syllabus 53

16 Assessment Schedule 54

17 Prescribed Text Books & Reference Books 55

18 Mini Project suggestions 56

4
2. COURSE OBJECTIVES

OBJECTIVES:

● Learn XML fundamental


● Be exposed to build applications based on XML.
● Understand the key principles behind SOA.
● Be familiar with the web services technology elements for
realizing SOAP.
● Learn the various web service standards

4 5
3. PRE REQUISITES

Pre-requisite Chart

Service Oriented Architecture

Cloud Computing

6
4. SYLLABUS

21CS923 SERVICE ORIENTED ARCHITECTURE L T P C


3 0 0 3

OBJECTIVES
● Learn XML fundamental
● Be exposed to build applications based on XML.
● Understand the key principles behind SOA.
● Be familiar with the web services technology elements for realizing SOAP.
● Learn the various web service standard

UNIT-1 INTRODUCTION TO XML 9

Fundamentals of XML : document structure – Well-formed and valid


documents – Namespaces –Validating XML with DTD - Creating XML Schema
– X-Files

UNIT-II BUILDING XML- BASED APPLICATION 9

Parsing XML: Using DOM, Using SAX – Transforming XML with XSL – XSL
Formatting – Modeling Databases in XML

UNIT-III ARCHITECTING WEB SERVICES 9

Web Services - Business Motivation For Web Services - CORBA and DCOM -
Service Oriented Architecture (SOA): Key Functional Components, Semantic
Issues and Taxonomies – Implementation Architectural View.

UNIT-IV WEB SERVICES BUILDING BLOCKS: SOAP 9

Introduction to SOAP - Syntax - Messages - Implementation - Future of SOAP.


Web Services Building Blocks: WSDL and UDDI

UNIT-V APPLIED XML 9

Understanding XML Standards: Standard Organization - Standard Stack Layer -


Standard Stack Aspects. Implementing XML in E-Business

7
5. COURSE OUTCOME

At the end of the course, the student should be able to:

COURSE OUTCOMES HKL

CO1: Understand the basic concepts of K2

CO2: Develop web services using technology elements K3

CO3: Implement architectural views K3

Build applications based on XML.


CO4: K3

Build SOA-based applications


CO5: K3

HKL = Highest Knowledge Level

7
8
6. CO - PO / PSO MAPPING

PROGRAM OUTCOMES (POs) PROGRAM


SPECIFIC
OUTCOMES
(PSOs)
P0 PO PO PO PO PO PO PO PO PO PO PO1 PSO PSO
COS PSO3
1 2 3 4 5 6 7 8 9 10 11 2 1 2

CO1 3 3 3 2 2 - - - - - - - 3 3 3

CO2 3 3 3 2 3 - - - - - - - 3 3 3

CO3 3 3 3 1 3 - - - - - - - 3 3 3

CO4 3 3 3 2 2 - - - - - - - 3 3 3

CO5 3 3 3 2 2 - - - - - - - 3 3 3

Correlation Level - 1. Slight (Low) 2. Moderate (Medium)


3. Substantial (High) , If there is no correlation, put “-“.

9
UNIT I
INTRODUCTION TO XML

10
INTRODUCTION TO XML
 XML stands for Extensible Markup Language and
is a text-based markup language derived from
Standard Generalized Markup Language (SGML).
Although derived from SGML, XML has simplified
the process of defining and using this metadata
 Extensible Markup Language (XML) is fast
becoming a standard for data exchange in the next
generation’s Internet applications. XML allows
user-defined tags that make XML document
handling more flexible
 XML stores data in plain text format. This provides
a software- and hardware- independent way of
storing, transporting, and sharing data.
 XML is a syntax for expressing structured data in a text
format
 XML is not a language on its own. Instead, XML is used
to build markup languages.
 XML was designed to store and transport data, but not to
display data.
 XML was designed to be both human- and machine-
readable.
 XML is a markup language much like HTML.But it is not
a replacement for HTML
 XML was designed to be self-descriptive
 XML is platform independent and language independent
 XML is a W3C Recommendation
 XML was originally called Web SGML, later
renamed the Extensible Markup Language(XML)

11
Introduction to XML
Xml Usage:
An XML can be:
 Used to exchange the information between organizations
and systems.
 Used for offloading and reloading of databases.
 Used to store and arrange the data, which can customize
your data handling needs.
 used extensively as Configuration files in J2EE
architectures and .Net architecture (web.config – in Asp.Net,
web.xml in Tomcat web server)
 Often used to separate data from presentation
 Easily merged with style sheets to create almost any desired output.
 Virtually, any type of data can be expressed as an XML document.
 In Visual Studio.Net, software installation is
made easy by using xml.Software installation is
simply done using xcopy. No more use of Windows
registry
 XML is complement to HTML
 XML is alternate to relational databases
 XML is universal standard EDI format(Electronic Data
Interchange format)
 Used for B2B transactions on the Web
:
o Electronic business orders (ebXML)
o Financial Exchange (IFX)
o Messaging exchange (SOAP)

12
Introduction to XML
Industry where XML are used:
For exchanging data between ograinzation in the Internet,
there are thousands of XML formats exist, for many
different industries, to describe day-to-day data transactions:
 Stocks and Shares
 Financial transactions
 Medical data
 Mathematical data

13
Well Formed XML documents / Rules of XML Structure

 A document is said to be well formed, only if it obeys


the syntax of XML
 Any XML document said to be "Well
Formed" XML document, if it satisfies the
following syntax rules:
An XML document must contain only one root element
and that must be the parent of all other elements
Correct Incorrect
<?xml version="1.0"?> <?xml version="1.0"?>

<catalog> <book>

<book> <title>C# complete reference</title>

<title>C# complete reference</title> <price>$20</price>

<price>$20</price> </book>

</book> <book>

<book> <title>XML step by step</title>

<title>XML step by step</title> <price>$30</price>

<price>$30</price> </book>

</book> Reason: contain more than one


root

</catalog> element <book>

Reason: contain only one root element

14
Well Formed XML documents / Rules of
XML Structure
All XML Container Elements Must Have a Closing Tag
Correct Incorrect

<?xml version="1.0"?> <?xml version="1.0"?>


<name> <name>

<first-name>kajendran</first- <first-name>kajendran
name> <last-name>krishnan</last-
<last-name>krishnan</last-name> name>

</name> </name>
Reason: element <first-name> does
not have closing tags

• Attribute Values Cannot Contain References to


External Entities
• All Entities Except amp, lt, gt, apos, and quot
must be declared before they are used
• A binary entity cannot be referenced in the
flow of content, it can only be used in an
attribute declared as ENTITY or
ENTITIES
• Neither text nor parameter entities are allowed to
be recursive, directly or indirectly

15
XML namespaces
 XML Namespaces provide a mechanism to
avoid element name conflicts and attribute
name conflict
 The main purpose of namespace is to group
elements and to differentiate an element
from others with a similar name
 XML namespaces provide a simple method
for qualifying element and attribute names
used in XML documents by associating them
with namespaces identified by URI
references
 Namespaces are a simple and
straightforward way to distinguish names
used in XML documents, no matter where
they come from
 Namespace is a mechanism by which
element and attribute name can be assigned
to group. The Namespace is identified by
URI(Uniform Resource Identifiers).
 In an XML document, the URI is associated
with a prefix, and this prefix is used with
each element to indicate to which namespace
the element belongs. For example:
rdf:description
xsl:template
In these examples,
o the part before the colon is the prefix
o the part after the colon is the local part
o any prefixed element is a qualified name
o any un-prefixed element is an unqualified
name

16
XML namespaces
Name Conflicts:
 In XML, element names are defined by the
developer. This often results in a conflict
when trying to mix XML documents from
different XML applications in large XML-
based distributed systems.
 For example, consider the following XML
document that carries information about
HTML table example:
<table>
<tr>
<td>Apples</td>
<td>Bananas</td>
</tr>
</table>
 The following is an XML document that carries
information about a table (a piece of furniture):
<table>
<name>African Coffee Table</name>
<width>80</width>
<length>120</length>
</table>
If these XML fragments were added together, there would be a name
conflict. Both contain a <table> element, but the elements have different
content and meaning

17
XML namespaces
Solving the Name Conflict Using a Prefix

 Name conflicts in XML can easily be avoided using a


name prefix. The following XML carries information
about an HTML table, and a piece of furniture:
<h:table>
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>

<f:table>
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table>
In the example above, there will be no conflict because the two
<table> elements have different names.
Drawback:
 If prefix itself same for more than one xml
document, then again name conflict occurs. To avoid
this we can use xml namespace along with prefix

18
XML namespaces
Solving name conflict using Namespace declaration

 The namespace can be defined by an xmlns attribute in the start tag


of an element.
The namespace declaration has the following syntax:
<element-name xmlns:prefix="URI">
Where

 The Namespace starts with the keyword xmlns.


 The word prefix is the Namespace prefix.
 The URI is the Namespace identifier.
 Consider the following example:
<root>
<h:table xmlns:h="http://www.w3.org/TR/html4/">
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>
<f:table xmlns:f="http:/ www.pepperfry.com /furniture">
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table>
</root>
 In the example above:
o The xmlns attribute in the first <table> element
gives the h: prefix a qualified namespace.
o The xmlns attribute in the second <table> element
gives the f: prefix a qualified namespace.
o When a namespace is defined for an element, all
child elements with the same prefix are associated
with the same namespace.

19
XML namespaces
 Namespaces can also be declared in the XML root element:
<root
xmlns:h="http://www.w3.org/TR/html4
/" xmlns:f="http:// www.pepperfry.com
/furniture">
<h:table>
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>
<f:table>
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table>
</root>
Note: The namespace URI is not used by the parser to look up information.
The purpose of using an URI is to give the namespace a unique name
 Notice that the prefi f, h, has been added to both the
start and the end tags and is followed by a colon and
then the element’s local name
 If you want the attributes in the document to be also in
the namespace then you follow a similar procedure as
shown in Listing:
<hr:ApplicationUsers
xlns:hr=”http://wrox.com/namespaces/applications/hr/config”>
<user hr:firstName=”Joe” hr:lastName=”Fawcett” />
<user hr:firstName=”Danny” hr:lastName=”Ayers” />
<user hr:firstName=”Catherine” hr:lastName=”Middleton” />
</hr:applicationUsers>
 The namespace prefi x is prepended to the attribute’s name and
followed by a colon

20
XML namespaces
Scope of Namespace
 The namespace declaration must come either on
the element that uses it or on one higher in the
tree, an ancestor as it’s often called
 The file content shown below is not wellformed
because the declaration is too far down the tree
and therefore not in scope:
<hr:applicationUsers>
<user
xmlns:hr=”http://wrox.com/names
paces/applications/hr/config”
firstName=”Joe”
lastName=”Fawcett” />
<user firstName=”Danny” lastName=”Ayers” />
<user firstName=”Catherine” lastName=”Middleton” />
</hr:applicationUsers>
Naming Namespaces
 XML namespace identifiers must conform to a
specific syntax—the syntax for Uniform Resource
Identifier (URI) references. This means that XML
namespace identifiers must follow the generic
syntax for URIs defined by RFC 2396.
 URI references are used to identify physical resources
(Web pages, files to download, and so on), but in the case
of XML namespaces, URI references identify abstract
resources, specifically, namespaces

21
XML namespaces
URLs, URIs, and URNs
URL specifies the location of a resource, for
example a web page, and how it can be retrieved. It
has the following format:
[Scheme]://[Domain]:[Port]/[Path]?[QueryString]#[
FragmentId]
The terms in square brackets are replaced by their
actual values and the rest of the items other than
Scheme and Domain are optional. So a typical web
URL would be
http://www.wrox.com/remtitle.cgi?isbn=0470114878
The scheme is HTTP, the domain is www.wrox.com,
followed by the path and a querystring. You can use many
other schemes, such as FTP and HTTPS, but the main point
about URLs is that they enable you to locate a resource,
whether that is a web page, a file, or something else.
Uniform Resource Identifier (URI)
 URI is just a unique string that identifies an
Internet Resource or something else
 According to the URI specification, there are two
general forms of URI:
o Uniform Resource Locators (URL) and
o Uniform Resource Names (URN)
 Either type of URI may be used as a namespace
identifier.

22
XML namespaces
URL
 The most common URI is the Uniform Resource
Locator (URL) which identifies an Internet domain
address that can be used as namespace identifier.
Here is an example of two URLs that could be used as
a namespace identifiers:
http://www.develop.com/student
http://www.ed.gov/elementary/stude
nts
 All URLs are also URIs but the opposite is not necessarily true.

URN
 Another, not so common type of URI is the Universal Resource
Name (URN).
 A URN is a name that uniquely defines something. URNs take
the following format:
urn:[namespace identifier]:[namespace specific string]

 The items in square brackets need to be replaced by


actual values and the three- character prefix, urn, is
not case-sensitive
 An example of a URN would be:
urn:isbn:9780470114872

 This URN uniquely identifi es the fourth edition of this


book, but because it’s a URN, not a URL, it doesn’t tell
you anything about how to retrieve either the book
itself or any information about it
 Here are a few examples of URNs that could also be
used as namespace identifiers: urn:www-
develop-com:student
urn:www.ed.gov:elementary.students
urn:uuid:E7F73B13-05FE-44ec-81CE-
F898C4A6CDB4

23
XML namespaces
Default Namespaces
Defining a default namespace for an element saves us from
using prefixes in all the child elements. It has the following
syntax:
<element-name xmlns="URI">
 This XML carries information about a piece of furniture:
<table xmlns="http://www.pepperfry.com/furniture ">
<name>African Coffee Table</name>
<width>80</width>
<length>120</length>
</table>
Declaring More Than One Namespace
number of choices when you need to design XML in this fashion
Option 1: choose a default namespace for some elements and
an explicit one for others.
 In the following example, we place the
<applicationUsers> element in the hr namespace
and the <user> elements themselves in a different
one, which is used by
<user> elements across all company documents
 hr namespace is created as the default and the
entities namespace created as explicit. You need a
prefix for the newer one so choose ent
<applicationUsers xmlns=”http://wrox.com/namespaces/hr”
xmlns:ent=”http://wrox.com/namespaces/entities”>
<ent:user firstName=”Kajendran” lastName=” Krishnan” />
<ent:user firstName=”Suresh” lastName=”Krishna” />
<ent:user firstName=”Ramesh” lastName=”Babu” />
<user name=”Ram Kumar” />
</applicationUsers>

24
XML namespaces
 Because both declarations are on the root element they are in scope
for the whole of the document. Therefore any elements without a
prefix fall into the hr namespace and any with an ent prefix fall into
the entities namespace

Option 2: make both namespace declarations explicit, to avoid a default namespace,


because it makes which element is grouped under which namespace not clear. An
example is given below:
<hr:applicationUsers xmlns:hr=”http://wrox.com/namespaces/hr”

xmlns:ent=”http://wrox.com/namespaces/entities”>
<ent:user firstName=”Kajendran” lastName=” Krishnan” />

<ent:user firstName=”Suresh” lastName=”Krishna” />

<ent:user firstName=”Ramesh” lastName=”Babu” />


<hr:user name=”Ram Kumar” />

</hr:applicationUsers>
Option 3:declaring a namespace twice with different prefixes. An example is given
below:
<hr1:applicationUsers xmlns:hr1=”http://wrox.com/namespaces/hr”
xmlns:hr2=”http://wrox.com/namespaces/hr”>

<hr2:user firstName=”Kajendran” lastName=” Krishnan” />

<hr2:user firstName=”Suresh” lastName=”Krishna” />


<hr2:user firstName=”Ramesh” lastName=”Babu” />

</hr1:applicationUsers>

Invalid namepace
 Note: As shown in the above example, there are more than one
prefix can point to the same namepace, it is well formed( or
namepspace-well-formed)
 But you cannot have the same prefix pointing to different
namespace URIs, as shown below:

<hr:applicationUsers xmlns:hr=”http://wrox.com/namespaces/hr”

xmlns:hr=”http://wrox.com/namespaces/entities”>
<hr:user firstName=”Kajendran” lastName=” Krishnan” />

<hr:user firstName=”Suresh” lastName=”Krishna” />


<hr:user firstName=”Ramesh” lastName=”Babu” />

</hr:applicationUsers>
The above example is not namespace–well-formed

25
DTD(Document Type Definition)

 A DTD defines the structure and the legal elements


and attributes of an XML document.
 The purpose of a DTD is to define the legal building blocks
of an XML document. It defines the document structure
with a list of legal elements
 DTD is used to validate the following in the XML document:
owhat are the elements allowed in the XML document
oin what order/sequence the elements should appear in the
XML document owhat are attributes of every element, and
whether it is optional or required owhat is the relation
between elements

Why Use a DTD?


 With a DTD, independent groups of people can agree
on a standard DTD for interchanging data.
 Your application can use a standard DTD to verify that data
that you receive from the outside world is valid.
 You can also use a DTD to verify your own data.
 There are two ways of associating a DTD with a XML document.
They are:
o internal DTD - A DTD can be declared inline in your XML
document
o External DTD- An XML document refers to external DTD

The Document Type Declaration(DOCTYPE)


 The Document Type Declaration, or DOCTYPE,
informs the parser that your document should conform
to a DTD
 It also indicates where the parser can find the rest of the definition
 Internal DTD is embedded within the xml document through
<!DOCTYPE>
 External DTD is linked with XML document through <!DOTTYPE>
 The generic structure of DOCTYPE declaration is shown below:
<!DOCTYPE ROOT-ELEMENT-NAME SYSTEM|PUBLIC “location1” “location2”
[…]>

26
DTD(Document Type Definition)
DOCTYPE with an Intenal DTD definition
 The simplest form of DOCTYPE declaration is given
below, which is used to define internal DTD:
<!DOCTYPE ROOT-ELEMENT-NAME [ ]>

An example of internal DTD is given below:


<?xml version=”1.0” ?>
<!DOCTYPE name [ <!ELEMENT name (first, middle, last)>
<!ELEMENT first (#PCDATA)>
<!ELEMENT middle (#PCDATA)>
<!ELEMENT last (#PCDATA)>
]>
<name>
<first>John</first>
<middle>Fitzgerald Johansen</middle>
<last>Doe</last>
</name>

DOCTYPE with an Extermal DTD definition


 For linking external DTD with XML Document, you must
use either SYSTEM or
PUBLIC in the DOCTYPE declaration
 SYSTEM identifier
o refers to a private DTD used by single organization
o Located on the local file system or HTTP server

 PUBLIC identifier
o refers to a DTD intended for public
use, and shared by multiple
organization

27
DTD(Document Type Definition)
System Identifiers

 A system identifier allows you to specify the location


of an external file containing DTD declarations. It is
comprised of two parts:
o the keyword SYSTEM and
o a URI reference pointing to the document’s location.
 A URI can be a file on your local hard drive, a file on
your intranet or network, or even a file available on
the Internet
 Syntax:
<!DOCTYPE ROOT-ELEMENT-NAME “DTD-file-name”>
 where DTD-file-name is the file with .dtd extension
 The following examplesuse system identifiers:
<!DOCTYPE name SYSTEM “file:///c:/name.dtd” [ ]>
<!DOCTYPE name SYSTEM “http://wiley.com/hr/name.dtd” [ ]>
<!DOCTYPE name SYSTEM “name.dtd”>
 Specifying an internal subset is optional.
 An XML document might conform to a DTD that uses
only an internal subset, only an external subset, or
both. If you do specify an internal subset, it appears
between the [ and ], immediately following the
system identifier

Public Identifiers
 Public identifiers provide a second mechanism to locate DTD
resources. Its syntax:
<!DOCTYPE root PUBLIC FPI-identifier URL>
 Using PUBLIC keyword allows non-specific reference
to the DTD via a URL, even perhaps via secondary
URL

28
DTD(Document Type Definition)
 Example: BookCatalog DTD could become a well
known publishing industry standard, in which case we
might refers to it using the following declaration:
<!DOCTYPE BookCatalog “-//publishingconsortium//bookcatalog”

http://www.wrox.com/dtd/bookcatalog.dtd”
>

 In this example, the xml application would have more flexibility


in locating the DTD.
 If the parser or application cannot locate the DTD
using primary (PUBLIC) location, the
second(SYSTEM) location is used. Note that SYSTEM
keyword is implied

 According to the XML specification, public identifiers


can follow any format; however, a commonly used
format is called Formal Public Identifiers( FPIs).
 The syntax for FPIs matches the following basic structure:
-//Owner//Class Description//Language//Version

 At the most basic level, public identifiers function


similarly to namespace names, but public identifiers
cannot be used to combine two different vocabularies
in the same document. This makes namespaces much
more powerful than public identifiers
An example of External DTD is given below:
(i) The first step is to define external DTD file
called “address.dtd”. Its content is shown below:
<!ELEMENT address (name,company,phone)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT company (#PCDATA)>
<!ELEMENT phone (#PCDATA)>

29
DTD(Document Type Definition)
(i) Next, create an “address.xml” file and link the
“address.dtd” as shown below:
<?xml version="1.0" encoding="UTF-8"
standalone="no" ?>
<!DOCTYPE address SYSTEM "address.dtd">
<address>
<name>Tanmay Patil</name>
<company>TutorialsPoint</company>
<phone>(011) 123-4567</phone>
</address>
ANATOMY OF A DTD/ Basic units of DTD / basic DTD
markup

There are four basic keyword used in DTD declaration,


which is listed below:
 Element declarations(ELEMENT)
 Attribute declarations(ATTLIST)
 Entity declarations(ENTITY)
 Notation declaration(NOTATION)
Element Declarations
 An element declaration can have one of two different forms:
<!ELEMENT element-name category>
- used for categories: EMPTY,ANY
<!ELEMENT element-name (element-content-model)>
- used for categories: #PCDATA,element, mixed

30
DTD(Document Type Definition)
As far as the XML Recommendation is concerned, there are
five categories of element content as listed below:

o EMPTY Element type may not contain any text or child elements,
only
attributes are permitted

o ANY Element type may contain any well-formed XML data. This could

includes character data


o #PCDATA Element type can contain text(character data) only
o Element Element type contain only child elements, but no additional text
is
permitted within this element type

o Mixed Element type may not contain text or child elements or


combination
of both

31
DTD(Document Type Definition)
EMPTY
 Element declared as EMPTY cannot contain
anything, except attributes. It means that the element
neither contain textual data nor contain child element
within it. Such as elements are known as empty
elements

Syntax: <!ELEMENT
element-name EMPTY>
Example: <!ELEMENT eof
EMPTY>
Valid xml: <eof />
o It could be
alternatively written
as <eof></eof>
Invalid xml:
<eof>end of
file</eof>

ANY
 Element declared as ANY can either contain textual
data or contains child element within it or combination
of both

Syntax: <!ELEMENT
element-name ANY>
Example: <!ELEMENT
PersonName ANY>

32
DTD(Document Type Definition)
Valid xml:
(i) <PersonName> Kajendran Krishnan </PersonName>
(ii) <PersonName>
Kajendran
<father>Krishnan</father>
</PersonName>
# PCDATA(text only)
 Element declared as #PCDATA can only contain text data
or character data. The text contents of an element should
not contain any special characters such as <,>,&,’,” etc.

Syntax: <!ELEMENT element-


name (#PCDATA)> Example:
<!ELEMENT name
(#PCDATA)>
Valid xml: <name> kajendran
krishnan</name> Invalid xml:
<name> rama <
krishnan</name>
element only
 Element declared as element content can only contain
other(child) elements, but it cannot contain parsed
character data
 When defining a content model with element content,
you simply include the allowable child elements within
parentheses separated by comma
 Here
o The child elements are constrained to appear in specific
sequence(sequence list)
o Child elements are also constrained to choose
only only child elements among several choice
(choice list)
o The number of occurance of child elements may
be specified by cardinality operators

Syntax:
<!ELEMENT element-name (child-element1, child-element2,…)>

33
DTD(Document Type Definition)
Syntax:
<!ELEMENT element-name (child-element1,
child-element2,…)>
Example:
<!ELEMENT address
(name,street,area,city,pincode)>
<!ELEMENT names (#PCDATA)>
<!ELEMENT street (#PCDATA)>
<!ELEMENT city (#PCDATA)>
<!ELEMENT pincode (#PCDATA)>
Valid xml: <address>
<name>kajendran</name>
<street>11, valluvar street</street>
<area>west saidapet</area>
<city>west saidapet</city>
<pincode>600015</pincode>
</address>
invalid xml: <address>
<name>kajendran</name>
<street>11, valluvar street</street>
<area>west saidapet</area>
<pincode>600015</pincode>
<city>chennai</city>
</address>
Reason:element <pincode> must only appear after the
element <city>

34
DTD(Document Type Definition)
mixed
 Element declared as mixed content can contain both text
data as well as child elements, or any other combination
 In mixed contenet model, child elements are constrained
to character data plus a simple list of valid child element
types, and child element must be defined withour any
sequence or choice specification further
 Example:
<!ELEMENT PersonName (#PCDATA, FatherName)>

 Valid xml:
o <PersonName>
Kajendran
<FatherName>Krishnan</FatherName>
</PersonName>

DTD Attribute Types – ENTITIES

The attribute type of ENTITIES allows you to refer to


multiple entity names, separated by a space:
Syntax:
<!ATTLIST element_name attribute_name ENTITIES
default_value>
Example:
<!ELEMENT mountains (mountain+) >
<!ELEMENT mountain (name) >
<!ATTLIST mountain photo ENTITIES #IMPLIED>
<!ENTITY mt_cook_1 SYSTEM "mt_cook1.jpg">
<!ENTITY mt_cook_2 SYSTEM "mt_cook2.jpg">
Valid XML - The following XML document would be
valid, as it conforms to the above DTD:
<mountains>

35
DTD(Document Type Definition)
<mountain photo="mt_cook_1 mt_cook_2">
<name>Mount Cook</name>
</mountain>
<mountain>
<name>Cradle Mountain</name>
</mountain>
</mountains>

(i) DTD Attribute Types : NOTATION


 The attribute type of NOTATION allows you to use a value that has
been declared as a notation in the DTD. A notation is used to specify the
format of non-XML data. A common use of notations is to describe MIME
types such as image/gif, image/jpeg etc
Syntax:
 To declare a notation:
<!NOTATION name SYSTEM "external_id">
To declare the attribute:
<!ATTLIST element_name attribute_name NOTATION default_value>
DTD Entity types
 These are the key to replaceable content in both DTDs and XML documents.
A general entity reference is used in the target XML document/s. The two
main categroies of entities are:

o General entities - They are usable within any XML document

o Parameter Entities- they may only be used with DTDs

Parsed entities
 It can be either internal or external.
 Internal: The actual replacement text is included with in the xml document
 External: the actual replacement text is located in external file or other resource
 The general syntax of parsed entity declaration is given below:
<!ENTITY entity-name "replacement-text">
 Once parsed entity is defined it can be referenced using the following syntax:
&entity-name;
 An example parsed entity declaration is given below:
<!ENTITY COPY "&#169">
 A reference of parsed entity from xml document is given below:
<copyright>&copy;</copyright>

36
DTD(Document Type Definition)
Unparsed entites
 To embed non-XML data (such as an image) into your
XML document, you need to treat it as an external
unparsed entity. To declare an external unparsed
entity, you use the <!ENTITY> declaration along
with the NDATA keyword.
 Unparsed entites are always external. All unparsed
entities can be referenced only from attributes of types
ENTITY or ENTITIES
 All unparsed entities must have an assoicated notation,
which is also identified by name
Syntax to declare unparsed entities:
<!ENTITY name SYSTEM value NDATA TYPE>
 You can also use public external unparsed entities by
using the PUBLIC keyword along with a Formal Public
Identifier (FPI):
<!ENTITY name PUBLIC FPI value NDATA TYPE>

Example
 Here's an example of a private external unparsed
entity. Here, we declare a new notation named "JPG"
for the "image/jpeg" MIME type. Then we declare an
external unparsed entity called "mt_cook_1" that
refers to an image file called "mt_cook1_jpg". We
then create a new attribute of type ENTITY - this
means that we can now use this attribute in our XML
document to refer to the unparsed external entity.
//definition of notation
<!NOTATION JPG SYSTEM "image/jpeg">
//definition of unparsed entities
<!ENTITY mt_cook_1 SYSTEM "mt_cook1.jpg"
NDATA JPG>
//declaration of attribute of ENTITY type
<!ATTLIST mountain photo ENTITY #IMPLIED>

37
DTD(Document Type Definition)
 After declaring the external unparsed entity in our DTD and creating an attribute of
type ENTITY, we can now embed it in our XML document:
<mountains>

<!-- reference of unparsed entity -->

<mountain photo="mt_cook_1">
<name>Mount Cook</name>
</mountain>
<mountain>

<name>Cradle Mountain</name>

</mountain>
</mountains>
Parameter entities
 These types of entites are used extensively in DTDs and must always parsed
entites. Paremeter entities are always convenient shorthand for repetitive DTD
declaration
 Parameter Entityis used within the DTD itself. In other words, you can create
an entity that can be used within your DTD declarations themselves.

Syntax
 When creating a parameter entity, you need to insert a percentage sign (%) between

ENTITY, and the name of the entity as shown


below

<!ENTITY % entity-name "replacement-text">


 You can also declare external parameter entities. You do this using the
following syntax

 Declaration of Private entity:

<!ENTITY % name SYSTEM uri>

 Declaration of Public entity:


<!ENTITY % name PUBLIC FPI uri>

 Once the parameter entity is defined, it can be referenced using the following syntax:
%entity-name;

<!ENTITY % idfef_req “IDREF #REQUIRED”>


<!ATTLIST book bookid ID #REQUIRED
publisher % idfef_req ;>

38
DTD(Document Type Definition)

Limitation of DTDs

The DTD has several shortcomings. First, a DTD document does not
have to be coded in XML.That means that a DTD is itself not an XML
document.
 Second, the data types available to define the contents of an attribute
or element are very limited in DTD
 Some limitation of DTD include:
o DTDs are not extensible
 DTD describes the rules of an XML vocabulary
 All those rules must be present in single DTD
 There is no mechanism for inclusion of mechanism from multiple
sources
 So not suitable for distributed environment
o Only one DTD may be associated with each XML document
 large DTDs are hard to read and maintain
o DTD do not work well with XML namespace
 All element names are global
–Is <name> for people or companies?
–can’t declare both in the same DTD
o Very week data typing
 There are no constraints imposed on the kind of
data(int,float, string, date, etc) allowed within XML
Element and Attribute, so datatyping is not possible
o Limited content model description
o No OO type object inheritance
 Describing one element type in terms of another is not possible in
DTD
o An XML document can override or ignore an external DTD
using internal subset
 Since the internal DTD has precedence over the external
subset, there is no assurance that the rules of a DTD will be
followied by XML document with which it is associated
o Non-XML syntax

39
DTD(Document Type Definition)
 They are not written in XML syntax, which means you have
to learn a new syntax in order to write them
 DTD do not use well formed XML Syntax
 Most of the DTD represemted in Extended Backus Naur Form(EBNF)
o No DOM support
 DOM is commonly used way to manipulate XML data, but
it does not
handle EBNF and provides no access to the rules of
document model in the DTD
o Relatively few older and more expensive tools
 DTD’s design goal of interoperabality with SGML and HTML,
XML
 However, most SGML tools are both expensive and complex

All xml document are comprised of unit of storage called entities.


For example document entity server as the entry point for an XML
parser
The internal and external subset of the DTD are also entities, but unnamed
one.
Other types of entites are always identified and referred to by
name. these are key replaceable content in both DTD

40
XML schema
The purpose of an XML Schema is to define the legal
building blocks of an XML document:
 The elements and attributes that can appear in a document
 The number of (and order of) child elements
 Data types for elements and attributes
 Default and fixed values for elements and attributes
Why to use XML Schema instead of DTD?
1. XML Schemas Support almost all data types
available in every programming languages
- One of the greatest strength of XML Schemas is
the support for data types, which makes easier:
 To describe allowable document content
 To validate the correctness of data
 To define data facets (restrictions on data)
 To define data patterns

2. XML Schemas use XML Syntax:


- Another great strength about XML Schemas is that they are
written in XML, so that:
 You don't have to learn a new language
 You can use your XML editor to edit your Schema files
 You can use your XML parser to parse your Schema files
 You can manipulate your Schema with the XML DOM
3. XML Schemas are extensible for future additions,
because they are written in XML.
- With an extensible Schema definition you can:
 Reuse your Schema in other Schemas
 Create your own data types derived from the standard
types
 Reference multiple schemas in the same document

41
XML schema
1. XML Schemas supports Secure
Data Communication
2. XSD is richer and more powerful than DTD.
3. XSD supports namespaces.
 Schema offers multiple vocabulary support based on namespae in xml
1. XSD is W3C recommendation.
2. XSD offers inheritance supports
 New data type can be defined, which inherits feature from existing
types, which may be pre-defined or user defined
1. Dynamic schema support
 Schema can be selected and modified dynamically
Creating XML Schema
- Step 1: The following declaration define complex
type with local scope(anonymous type
declaration)for validating structure of the note.xml
file:
<?xml version="1.0"?>
<xs:schema
xmlns:xs="http://www.w
3.org/2001/XMLSchema"
targetNamespace="http:/
/www.xyz.com" >
<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>

42
XML schema
Step 2: A Referencing an XML Schema from XML
document(or) linking Schema with XML Document
<?xml version="1.0"?>
<note
xmlns="http://www.xyz.com"
xmlns:xsi="http://www.w3.org/2001/XM
LSchema-instance"
xsi:schemaLocation="http://www.xyz.co
m note.xsd">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
Components of XML Schema
 The <schema> Element
 The <element> Element
 The <attribute> Element
 The <simpleType> Element

 The <complexType> Element

 The <annatotation>
o The <documentation> Element
o The<appinfo> Element
The Schema Element

 The <schema> element is the root element of every XML Schema.


 The <schema> element may contain some attributes.
<?xml version="1.0"?>
<xs:schema
xmlns:xs="http://www.w3.org/
2001/XMLSchema"
targetNamespace="http://www.
xyz.com"
elementFormDefault="qualified
">

43
XML schema
 It indicates that the elements and data types used in the
schema come from the
“http://www.w3.org/2001/XMLSchema” namespace.
 It also specifies that the elements and data types that come
from the
"http://www.w3.org/2001/XMLSchema" namespace should be
prefixed with xs

This fragment: targetNamespace="http://www.xyz.com"


 indicates that the default namespace is "http://www.xyz.com".

This fragment: elementFormDefault="qualified"


 indicates that any elements used by the XML instance
document which were declared in this schema must be
namespace qualified.

Referencing a Schema in an XML Document


This XML document has a reference to an XML Schema:
<?xml version="1.0"?>
<note xmlns="http://www.xyz.com"
xmlns:xsi="http://www.w3.org/2001/
XMLSchema-instance"
xsi:schemaLocation="http://www.xyz.
com
note.xsd">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

The following fragment:


xmlns="http://www.xyz.com"

44
XML schema
 Specifies the default namespace declaration. This
declaration tells the schema- validator that all the
elements used in this XML document are
declared in the "http://www.xyz.com"
namespace
 You can use the schemaLocation attribute. This
attribute has two values, separated by a space. The
first value is the namespace to use. The second
value is the location of the XML schema to use for
that namespace:
xsi:schemaLocation="http://www.xyz.com
note.xsd"
XSD Simple Elements definition
- A simple element is an XML element that contains
only text. It cannot contain any other elements or
attributes.
- The text can be of many different types. It can be
one of the types included in the XML Schema
definition (boolean, string, date, etc.), or it can be a
custom type that you can define yourself.
- You can also add restrictions (facets) to a data type
in order to limit its content, or you can require the
data to match a specific pattern.
- The syntax for defining a simple element is:
<xs:element name="elementname"
type="data-type-name"/>
- The following example is a schema with four
simple elements named "fname", "lname", "age",
and "dateborn", which are of type string,
nonNegativeInteger, and date:

45
XML schema
Schema Simple element definition Valid xml example
<xs:element name="sname" type="xs:string"/> <name>ram</name>

<xs:element name="age" type="xs:nonNegativeInteger"/> <age>22</age>


<xs:element name="dateborn" type="xs:date"/> <dateborn>1970-03-7
</dateborn>
<xs:element name="NativeIndia" type="xs:boolean"/> <NativeIndia>
true
</NativeIndia>

Default and Fixed Values for Simple Elements


 Simple elements may have a default value OR a fixed
value specified.
<element> with default value:
 A default value is automatically assigned to
the element when no other value is
specified.
 In the following example the default value is "red":
<xs:element name="color" type="xs:string"
default="red"/>
<element> with fixed value:
 A fixed value is also automatically assigned to
the element, and you cannot specify another
value.
 In the following example the fixed value for company
name element is "panimalar":
<xs:element name="company Name" type="xs:string"
fixed="panimalar"/>

46
XML schema
XSD Complex Elements definition
- An element’s type can be defined with either a
<complexType> element, a
<simpleType> element, a <complexContent> element, or
a <simpleContent>
element
- Simple elements are defined with <simpleType>,
where as complex elements can be defined with
<complexType> element
- Complex element definition describe structure of
entire xml document or the structure of complex
elements.complex elmenents will haves other elements
as its children
- The following example defines complex element type called
<xsd:element name="PersonName">
<xsd:complexType content="elementOnly">
<xsd:sequence>
<xsd:element name="FirstName" type ="text"
minOccurs="1"/>
<xsd:element name="MiddleName" type
="text" minOccurs="0"
maxO
ccurs
="1"
/>
<xsd:element name="LastName" type ="text"
minOccurs="1" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
Valid XML that conform to Schema:
<PersonName>
<FirstName>Rajarajan</FirstName>
<LastName>Rajendran</LastName>
47
</personname>
The X-Files: XPath,XPointer, and XLink

XPath Introduction
 XPath is used to navigate through elements and attributes and
find data within your XML documents.
 XPath is a major element in W3C's XSLT standard.
 Using XPath, you can select one or more nodes in order to
retrieve the data they contain. XPath is used quite
extensively with XSLT.

What is XPath?
 XPath is a syntax for defining parts of an XML document
 XPath uses path expressions to navigate in XML documents
 XPath contains a library of standard functions
 XPath is a major element in XSLT
 XPath is a W3C recommendation

XPath Path Expressions


XPath uses path expressions to select nodes or node-sets in an
XML document. These path expressions look very much like the
expressions you see when you work with a traditional computer
file system.

XPath Standard Functions


XPath includes over 100 built-in functions. There are functions
for string values, numeric values, date and time comparison,
node and QName manipulation, sequence manipulation, Boolean
values, and more.

XPath is Used in XSLT


XPath is a major element in the XSLT standard. Without XPath
knowledge you will not be able to create XSLT documents.

XPath is a W3C Recommendation


XPath became a W3C Recommendation 16. November 1999.
XPath was designed to be used by XSLT, XPointer and other XML
parsing software.

48
The X-Files: XPath,XPointer, and XLink
XPath Purpose

 Since XPath is used for finding data


within XML documents, this enables XPointer
you to write applications that make XQuery XLink

 use of the data within an XML


 document. In order to use XSLT (to XPath

transform the contents of your XML


documents), you need to use XPath.
Other XML based languages such as
XQuery and XPointer also rely on
XPath expressions, so XPath really XSLT

does play an important role when


writing XML applications.

49
XPath
Xpath Terminology:
XPath Nodes:
In XPath, there are seven kinds of nodes: element, attribute, text,
namespace, processing-instruction, comment, and document nodes.
XML documents are treated as trees of nodes. The top most element of the tree is called
the root element.

Look at the following XML document:


<?xml version="1.0" encoding="UTF-8"?>

<bookstore>

<book>

<title lang="en">Harry Potter</title>

<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>

</book>
</bookstore>
Example of nodes in the XML document above:

 <bookstore> (root element node)


 <author>J K. Rowling</author> (element node)
 lang="en" (attribute node)

Atomic values

 Atomic values are nodes with no children or parent.

Relationship of Nodes
 Consider the following example. We will describe relationship of the nodes with the
following example:
<book>

<title>Harry Potter</title>

<author>J K. Rowling</author>

<year>2005</year>

<price>29.99</price>
</book>

50
XPath
Parent:
 Each element and attribute has one parent.
 In the above example; the <book> element is the parent
of the <title>, <author>,
<year>, and <price>

Children:
 Element nodes may have zero, one or more children.
 In the above example; the <title>, <author>,
<year>, and <price> elements are all children of
the <book> element
Siblings:
 Nodes that have the same parent.
 In the above example; the <title>, <author>,
<year>, and <price> elements are all siblings

Ancestors:
 A node's parent, parent's parent, etc.
 In the above example; the ancestors of the <title>
element are the <book>
element and the <bookstore> element
Descendants
 A node's children, children's children, etc.
 In the above example; descendants of the
<bookstore> element are the
<book>, <title>, <author>, <year>, and <price>
elements

51
XPath
XPath Syntax
XPath uses path expressions to select nodes or
node-sets in an XML document. The node is
selected by following a path or steps
We will use the following XML document in the examples
below.
<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book>
<title lang="en">Harry Potter</title>
<price>29.99</price>
</book>
<book>
<title lang="en">Learning XML</title>
<price>39.95</price>
</book>
</bookstore>
Selecting Nodes:
Expression Description
Nodename Selects all nodes with the name "nodename"
Selecting
/ Nodes
Selects from the root node
// Selects nodes in the document from the current node that
match
the selection no matter where they are

. Selects the current node


.. Selects the parent of the current node
@ Selects attributes

52
XPath
In the table below we have listed some path expressions and
the result of the expressions:

Path Expression Result

Bookstore Selects all nodes with the name "bookstore"

/bookstore Selects the root element bookstore


Note: If the path starts with a slash ( / ) it always represents
an absolute path to an element!

bookstore/book Selects all book elements that are children of bookstore

//book Selects all book elements no matter where they are in the
document

bookstore//book Selects all book elements that are descendant of the


bookstore
element, no matter where they are under the bookstore element

//@lang Selects all attributes that are named lang

53
XPath
Xpath Location Path:
To select a node (or set of nodes) in XPath, you use a location
path. A location path is used to specify the exact path to the
node you need to select
Consider the following xml document:
<albums>
<rock>
<title>Machine Head</title>
<artist>Deep Purple</artist>
</rock>
<blues>
<title>Greens From The Garden</title>
<artist>Cory Harris</artist>
</blues>
<country>
<title>The Ranch</title>
<artist>The Ranch</artist>
</country>
</albums>
- Now, here's a simple XPath expression to select the "title" node:
albums/rock/title
- The above expression would result in the first "title" node being
selected:
<title>Machine Head</title>
- If we wanted to select the artist instead, we would use this location
path:
albums/rock/artist
- The above expression would select the first "artist" node instead:
<artist>Deep Purple</artist>

54
XPath
Location Path Expression
 A location path can be absolute or relative.
Absolute path
 An absolute location path starts with a slash ( / ) and a relative
location path does not. In both cases the location path consists
of one or more steps, each separated by a slash:
 An absolute location path:
/step/step/...
 Where each step is evaluated against the nodes in the current
node-set. A step consists of:
o an axis (defines the tree-relationship between the selected nodes and
the current node)
o a node-test (identifies a node within an axis)
o zero or more predicates (to further refine the selected node-set)

 The syntax for a location step is:


axisname::nodetest[predicate]

 Consider the XML document given above. In that, if you wanted to select the "title"

node of all albums, we could use the following (absolute) location paths:
albums/rock/title
albums/blues/title
albums/country/title
 Here are the nodes that are selected using the above location path.
<title>Machine Head</title>
<title>Greens From The Garden</title>
<title>The Ranch</title>

 Selecting root node:


o If we wanted to select the root node, we could use either the node's
name or a forward slash. Both of these options are absolute location
paths and select the root node.
Option 1 - use the root node's name:
Albums

Option 2 - use a forward slash:

55
XPath
Relative path:
 If your location path begins with the name of a
descendant, you're using a relative location
path. This node is referred to as the context
node.
 A relative location path is one where the path starts
from the node of your choosing- it doesn't need to
start from the root node.
 A relative location path:
step/step/...
 Consider the following XML document:
 If we wanted to select the "title" node of all
albums, we could use the following (relative)
location path:

56
XLink
 XLink is used to create hyperlinks within XML documents
 Any element in an XML document can behave as a link
 With XLink, the links can be defined outside the linked
files
XLink is a W3C Recommendation
XLink Attribute Reference
Attribute Value Description

xlink:actuate onLoad Defines when the linked resource is read or retrieved


onReques and shown. The possible values are:
t other  onLoad - the resource should be loaded and shown
none when the document loads
 onRequest - the resource is not read or shown before
xlink:role qName It is the link
used in isextended
clicked link. This attribute provides a
machine
readable label
xlink:href URL Specifies the URL to retrieve external resource

xlink:title Some text It is used in extended link. This attribute provides a


human
readable label
xlink:show embe Specifies where to open the link. Default is "replace"
d new replace – replace the current content with target
replac resource new – open in the new window
e embed- embed target resource along with current content.
other It is like <img> tag in html
none
xlink:type simple Specifies the type of link
extende Simple - used to create external link similar to <a href>
d locator in Html
arc Extended – used to create link with m multiple resource.
resource All other types are as child-element of extended link
title
none
xlink:from qName The xlink:from and xlink:to attributes are used only with
& xlink:to extended link. The value of xlink:from and xlink:to
attribute are qName
They are used to define direction of the link

57
XLink
Types of link:
Simple link
- It provides the same functionality as hyperlink(<a> -
anchor
element)
provided to html
- They are the one way link, involving only two resources: the
source and destination
- example of simple link given below:
<?xml version="1.0"?>
<person xmlns:xlink="http://www.w3.org/1999/xlink">
<name
xlink:type="simple"
xlink:h
ref="name.xml"
xlink:actuate="onLoad"
xlink:s
how="embed"/>
<picture
xlink:type="simple"
xlink:href="picture.jpg"
xlink:actuate="onLoad"
xli
nk:show="embed"
xlink:title="Click to see picture!"> Click here to see a
picture! </picture>
<homepage xlink:type="simple"
xlink:href="http://www.xyz.com/homepag
es/persona1.htm"
xlink:actuate="onRequest"
xlink:show="replace">Click here for the
homepage</homepage>
</person>

58
XLink
- Extended link is the one that associate any number of
resources.
- They allows you to specify complex traversal rule between
various resources
- An external link can be either inline or out of line
(i) inline- if link’s one of the resource is in the same xml
document then it is referred to as inline
(ii) out of line – if all of the link recources are remote
- an extended resource con have one or more child
elements, which define the local and remote
resources participating in the extended link,
traversal rules for those resources
- extended type element can have the semantic
attributes: role and title, which define machine and
human readable label for the link
locator type elements
- They are child element of extended type elements
- It is used to indicate remote resource taking part in an
extended link
- locater type element must include href attributres.
Optionally it can include title and role attribute alos
arc type elements
- arc type element define the direction in which the link must
traverse using from and to
attributes
- it also define the behavior that the link follow when it retrieve
the resources using
show and actuate attributes
- except href, all other xlink’s attributes can be used in arc-type
element

59
XLink
resource type elements
- They are used to create local resource
- An extended link can be inline, if atleast one of the resource
specified is local
- These types of element can only have role and title attribute,
both are optional

title type elements


- the benfit of using title type element, instead of title
attribute is that the elements such as <B>,<U> can
included within the text
example: The example, define extended link, with
about three resource-type elements and three arc-type-
elements and two locator-type elements
<PartNumber
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:op="http://sernaferna.com/OrderProcessi
ngSystem" xlink:type="extended">
<item xlink:type="resource" xlink:role="op:item"
xlink:title="
Item">
<part-number>E16-25A</part-number>
<description>Production-Class Widget</description>
</item>
<salesperson xlink:type="locator"
xlink:href="http://sernaferna.com/order256.xml#xpoi
nter(/order/name)" xlink:role="op:salesperson"
xlink:title="Salesperson"
/>
<order xlink:type="locator"
xlink:href="http://sernaferna.com/order256.x
ml" xlink:role="op:order" xlink:title="Order"/>

60
XLink
<GetOrder xlink:type="arc"
xlink:from="op
:salesperson" xlink:to="op:order"
xlink:show="replace"
xlink:actuate="onRequest"
xlink:role="op:GetOrder"
xlink:title="Last order
processed."/>
<GetSalesperson
xlink:type="arc"
xlink:from
="op:order"
xlink:to="op:salesperson"
xlink:show="replace"
xlink:actuate="onRequest"
xlink:role="op:GetSalesperson"
xlink:title="Salesperson's
name"/>
<GetItemOrder
xlink:type="arc"
xlink:from="op:it
em"
xlink:to="op:ord
er"
xlink:show="new
"
xlink:actuate="o
nRequest"
xlink:role="op:G
etItemOrder"
xlink:title="Last order placed for this item"/>
</Partnumber>

61
XLink
Xpointer:
 Pointer allows links to point to specific parts of an XML
document
 XPointer uses XPath expressions to navigate in the XML
document
 XPointer is a W3C Recommendation
XPointer Example
- In this example, we will use XPointer in conjunction
with XLink to point to a specific part of another
document.
Instead of linking to the entire document (as with XLink),
XPointer allows you to link to specific parts of the
document. To link to a specific part of a page, add a
number sign (#) and an XPointer expression after the URL in
the xlink:href attribute, like this:
xlink:href="http://dog.com/dogbreeds.xml#xpointer(id('Ro
ttweiler'))".
expression refers to the element in the target
document, with the id value of "Rottweiler"
- The following XML document contains links to
more information of the dog breed for each of my
dogs:
<?xml version="1.0" encoding="UTF-8"?>
<mydogs xmlns:xlink="http://www.w3.org/1999/xlink">
<mydog>
<description>
Anton is my favorite dog. He has won a lot of.....
</description>

62
XLink
<fact xlink:type="simple" xlink:href="http://dog.com/dogbreeds.xml#Rottweiler">

Fact about Rottweiler


</fact>

</mydog>
<mydog>

<description>

Pluto is the sweetest dog on earth......


</description>

<fact xlink:type="simple" xlink:href="http://dog.com/dogbreeds.xml#FCRetriever">


Fact about flat-coated Retriever

</fact>
</mydog>

</mydogs>
XPointer short hand syntax:
In addition to the full Xpointer syntax, there are also a couple of shorthand syntaxes available. They are

 The Bare name syntax


 The child sequence syntax
Consider the following xml document, with an ID attribute(names.xml):

<?xml version= "1.0 " ?>

<!DOCTYPE order [ <!ELEMENT order (name, item, quantity,date)>

<!ELEMENT name (first, middle, last)>


<!ELEMENT first (#PCDATA)>
<!ELEMENT middle (#PCDATA)>

<!ELEMENT last (#PCDATA)>

<!ELEMENT item (#PCDATA)>

<!ELEMENT quantity (#PCDATA)>

<!ELEMENT date (#PCDATA)>


<!ATTLIST first id ID #REQUIRED> ]>
<order>

63
XLink

<name>
first id="section-1">John</first>
<middle>Kennady</middle>
<last>Doe</last>
</name>
<item>production-class widget</item>
<quantity>16</quanity>
<date>12.12.15</date>
</order>
FullX Pointer Syntax:
- The common usage of XPointer will be retrieving an
element from an XML document based on its ID. The
full syntax for the href attribute would be like this:
http://www.xyz.com/names.xml#xpointer(id("section-
1"))
The child sequence syntax:
- In the third way, we can specify XPointer expression at
the end of the URI is to use a child sequence:
http://www.xyz.com/names.xml#/1/1/2
- which says to select the second child of the first child
of the document root. In this case, it is the <middle>
element
- The number after / are child element numbers of previously
selected elements
- This expression means that “the second child
element of first child element of first child element”.
When used right at the beginning of the child
sequence, /1 means the root element. This XPointer
expression is equivalent to:
http://www.xyz.com/names.xml#xpointer(/*[1]/*[
1]/*[2])

64
11. PART A : Q & A : UNIT – I

1. What is the difference between Document Type Declaration


(DOCTYPE) and Document Type Definition (DTD)?
 A Document Type Declaration (DOCTYPE) and a DTD
serve very different, although related purposes. The
DOCTYPE is used to identify and name the XML
content, whereas the DTD is used to validate the metadata
contained within.

2. Why should we avoid XML-attributes and use sub-element in


xml definition?(or) What is the different between attribute and
sub-element?
 Generally, attributes are used to store Metadata, where as
sub-elements are suer to store actual data
 Attributes cannot contain multiple values, whereas child
elements can have multiple values.
 Attributes are not easily expandable. If you want to
change in attribute's vales in future, it may be complicated.
 Attributes cannot describe structure, but child elements can.
 Attributes are more difficult to be manipulated by program code.
 Attributes values are not easy to test against a DTD

3. Is XML declaration is processing instruction?


 It seems like yes, but Xml declaration is not processing instruction
 Because, it provides instruction to the parser, but not to the
application
4. What is XML processor (or) Parser?
 It is a software module used to read xml documents and
provides access to their content and structure
 It is doing its work onbehalf of another module called the
application
 Xml processors is more commonly called Parsers

65
10. ASSIGNMENT : UNIT – I
1. To Develop and Design Medical and Health care Application using
Microservice architecture? Justify why it is so important?
2. To implement Develop an Online Shopping service Application
using Microservice architecture with advantages and
disadvantages?

66
PART A : Q & A : UNIT – I
5. Why do we need XML namespaces?
There are really two fundamental needs for namespaces:
- To disambiguate between two elements that happen to share the same name
- To group elements relating to a common idea together
6. What is Qualified Name (or) QName?
An element or attribute name with a prefi x is known as a Qualified Name,
often abbreviated to QName. The part after the prefi x is technically known as a
Local Name
7. What is the drawback attribute? (OR) compare attribute with child
element?
 attributes cannot contain multiple values (child elements can)
 attributes are not easily expandable (for future changes)
 attributes cannot describe structures (child elements can)
 attributes are more difficult to manipulate by program code

8. What is the benefits of an XML Editor than text editor?


- An XML editor will help prevent you from making errors, while typing xml
file
- XML editors are similar to HTML editors (or any other
programming editor) in that they provide syntax highlighting
which helps with readability when you're coding.
- They'll automatically insert a closing tag once you're added an opening tag
- A good XML editor should also provide validation - a way for you
to validate that the documents you create are well formed.
9. List some examples of XML Editors?
- XML Notepad
- XML Cooktop
- XML Pro
- XML Spy
- Liquid XML Studio

67
PART A : Q & A : UNIT – I

10. In XML, the element can have what types of content?


In, XML the elements can have 4 content types:
 Text only – elements consists its content as text
o Example: <firstname>Kajendran</firstname>
 Element-only – elements consists entirely of nested elements
o Example
<name>
<firstname>Kajendran</firstname>
<middlename/>
<lastname>Krishnan</lastname>
</name>
 Mixed content – elements consist of combination of nested elements
and text
<address>
<name>
<firstname>Kajendran</firstname>
<lastname>Krishnan</lastname>

- </name>
- 11/20, valluvar street
- Saidapet west
- </address>
 Empty content
o Example:<name firstname=”ram” lastname=”kumar” />

68
13. SUPPORTIVE ONLINE CERTIFICATION COURSES
UNIT – I

Edureka - Microservices Certification Training Course

https://www.edureka.co/microservices-architecture-training?utm_source=Google-
Search&utm_medium=cpc&utm_campaign=ET-IND-006-Restructure-Microservices-
Architecture&gclid=CjwKCAjwivemBhBhEiwAJxNWN6tb0-UOeiUUv2vnB8ue43mEk5L5I-
0eOyb5xBw6by2NFNT-kFT38BoClMIQAvD_BwE

Udemy - Master Microservices with Spring Boot and Spring Cloud

https://www.udemy.com/course/microservices-with-spring-boot-and-spring-
cloud/?gclid=CjwKCAjwivemBhBhEiwAJxNWN0TZkYPDFl2ZOKIdyoWk2UVFZ4PxuT3joBll53km13Y_
gKhuJHUSfhoCI7gQAvD_BwE&matchtype=b&utm_campaign=LongTail_la.EN_cc.INDIA&utm_cont
ent=deal4584&utm_medium=udemyads&utm_source=adwords&utm_term=_._ag_78279325439_
._ad_533133844692_._kw_microservices+tutorial_._de_c_._dm__._pl__._ti_kwd-
339883804024_._li_9299769_._pd__._

Coursera - Building Scalable Java Microservices with Spring Boot and Spring Cloud

https://www.coursera.org/learn/google-cloud-java-spring

80

69
14. REAL TIME APPLICATIONS : UNIT – I
1. Walmart

Walmart switched to microservice architecture in 2012 after a string of system issues


during seasonal peaks of customer activity. The system could not handle the workload.
This issue resulted in a decrease in revenue. After this, Walmart made a complete
overhaul of its system and re-platformed core business tasks to microservices. This
approach allowed to redistribute the workload, and at the same time, streamline the
workflow of the system. In turn, this enabled further refinement of the framework.

2. Spotify

Spotify is another prominent example of using microservices to build an efficient system


and avoid the challenges of monolithic complex systems. At the moment, Spotify has over
75 million active users per month. That’s quite a scope to scale. These users don’t want
to think about the service, so the goal is to make the customer experience seamless.

3. Paypal

Microservices architecture is a perfect fit for payment processing. Workflow is structured,


and you don’t need to bend over backward to connect the parts of the workflow. As a
payment processor, Paypal’s scope of operation and customer demand is immense. The
service needs to be scalable to handle the load properly. In addition to consistent service,
the company needs to provide a decent customer experience. It is a challenge considering
the scope of operation.

4. Amazon

Amazon has the most interesting microservice use case because of its sheer scope. Let’s
take a look at the eCommerce Amazon application.The service encompasses multiple
operations with high workload requirements. There are personalization, notification, search
features, price optimization, advertisements, and other features at play. All of them manage
the proceedings through APIs.

5. PassportScan

PassportScan is using microservice architecture to handle different aspects of the operation


and keep the workflow smooth and sound. Microservices cover the following elements:

• User account management


• Data storage for sensitive information
70
• Booking component
16. ASSESSMENT SCHEDULE

Tentative schedule for the Assessment During 2024-2025


Odd semester

Name of the
S.NO Start Date End Date Portion
Assessment

1 Unit Test 1 UNIT 1

2 FIAT UNIT 1 & 2

3 Unit Test 2 UNIT 3

4 SIAT 2 UNIT 3 & 4

5 Model All 5 Units

163

71
17. PRESCRIBED TEXT BOOKS & REFERENCE
BOOKS

TEXTBOOKS:

1. Ron Schmeltzer et al. “XML and Web Services”, Pearson Education, 2002.
REFERENCES:

1. Thomas Erl, “Service Oriented Architecture: Concepts, Technology, and


Design”, PearsonEducation, 2005
2. Frank P.Coyle, “XML, Web Services and the Data Revolution”, Pearson
Education, 2002
3. Eric Newcomer, Greg Lomow, “Understanding SOA with Web Services”,
Pearson Education, 2005
4. Sandeep Chatterjee and James Webber, “Developing Enterprise Web
Services: An Architect's Guide”, Prentice Hall, 2004
5. James McGovern, Sameer Tyagi, Michael E.Stevens, Sunil Mathew,
“Java Web ServicesArchitecture”, Morgan Kaufmann Publishers, 2003.

72
18. MINI PROJECT SUGGESTION

Shopping Cart App

This is a shopping cart application developed using Microservice


Architecture with Spring Boot, Spring Cloud.
Here are the microservices:
1.catalog-service: It provides REST API to provide catalog information like
products.
2.inventory-service: It provides a REST API to manage product inventory.
3.cart-service: It provides a REST API to hold the customer cart details.
4.order-service: It provides a REST API to manage orders.
5.customer-service: It provides a REST API to manage customer
information.
6.shoppingcart-ui: It is customer-facing front-end web application.
GitHub repository link at https://github.com/sivaprasadreddy/spring-boot-
microservices-series.
Step by step tutorial series at https://sivalabs.in/categories/microservices/

73
Thank you

Disclaimer:

This document is confidential and intended solely for the educational purpose of
RMK Group of Educational Institutions. If you have received this document through
email in error, please notify the system manager. This document contains proprietary
information and is intended only to the respective group / learning community as
intended. If you are not the addressee you should not disseminate, distribute or
copy through e-mail. Please notify the sender immediately by e-mail if you have
received this document by mistake and delete this document from your system. If
you are not the intended recipient you are notified that disclosing, copying,
distributing or taking any action in reliance on the contents of this information is
strictly prohibited.

74

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy