UNIT-1 SOA - 21CS913 - Digital Notes
UNIT-1 SOA - 21CS913 - Digital Notes
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
7 Unit – I
Lecture Plan 11
Lecture notes 13
Assignments 47
Part A Q & A 48
Part B Qs 50
16 Assessment Schedule 54
4
2. COURSE OBJECTIVES
OBJECTIVES:
4 5
3. PRE REQUISITES
Pre-requisite Chart
Cloud Computing
6
4. SYLLABUS
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
Parsing XML: Using DOM, Using SAX – Transforming XML with XSL – XSL
Formatting – Modeling Databases in XML
Web Services - Business Motivation For Web Services - CORBA and DCOM -
Service Oriented Architecture (SOA): Key Functional Components, Semantic
Issues and Taxonomies – Implementation Architectural View.
7
5. COURSE OUTCOME
7
8
6. CO - PO / PSO MAPPING
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
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
<catalog> <book>
<price>$20</price> </book>
</book> <book>
<price>$30</price> </book>
14
Well Formed XML documents / Rules of
XML Structure
All XML Container Elements Must Have a Closing Tag
Correct Incorrect
<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
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
<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
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]
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
xmlns:ent=”http://wrox.com/namespaces/entities”>
<ent:user firstName=”Kajendran” lastName=” Krishnan” />
</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”>
</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:applicationUsers>
The above example is not namespace–well-formed
25
DTD(Document Type Definition)
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 [ ]>
PUBLIC identifier
o refers to a DTD intended for public
use, and shared by multiple
organization
27
DTD(Document Type Definition)
System Identifiers
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”
>
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
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
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 (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>
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>
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 "©">
A reference of parsed entity from xml document is given below:
<copyright>©</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>
<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
Once the parameter entity is defined, it can be referenced using the following syntax:
%entity-name;
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
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
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 <annatotation>
o The <documentation> Element
o The<appinfo> Element
The Schema Element
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
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>
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
48
The X-Files: XPath,XPointer, and XLink
XPath Purpose
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.
<bookstore>
<book>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
</bookstore>
Example of nodes in the XML document above:
Atomic values
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
52
XPath
In the table below we have listed some path expressions and
the result of the expressions:
//book Selects all book elements no matter where they are in the
document
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)
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>
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
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
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">
</mydog>
<mydog>
<description>
</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
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
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
67
PART A : Q & A : UNIT – I
- </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
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
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
2. Spotify
3. Paypal
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
Name of the
S.NO Start Date End Date Portion
Assessment
163
71
17. PRESCRIBED TEXT BOOKS & REFERENCE
BOOKS
TEXTBOOKS:
1. Ron Schmeltzer et al. “XML and Web Services”, Pearson Education, 2002.
REFERENCES:
72
18. MINI PROJECT SUGGESTION
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