Вы находитесь на странице: 1из 26

Unit 1

What is XML?
• XML stands for Extensible Markup Language
• XML is a markup language much like HTML
• XML was designed to describe data and transfer data over web.
• XML tags are not predefined. we must define our own tags
• XML uses a Document Type Definition (DTD) or an XML Schema to describe
the data
• XML with a DTD or XML Schema is designed to be self-descriptive .
• XML is a W3C Recommendation
• XML is independent of hardware, software and platform
**************************************************************
Benefits of XML

1.Structured document

Since XML documents are in structured format, it is easy to exchange data. For
example, let’s take the inventory of book example.

<inventory>
<book>
<title> xml and web services </title>
<author> Pearson education </author>
</book>
</inventory>

2.Simple

XML is simple in nature. It follows only simple syntax rules .It is in the human
readable format .

3.Validation of structure

We also can define the structure of an XML document using DTD or schema.
Especially, schema guarantees for the value of element content. Through DTD,or
schema , the document can be validated without human intervention. It can be
checked at the time of creation or at the time receipt.
4.Usage of Existing protocols

XML takes the advantages of existing Internet protocols such as HTTP for data
transfer between sender and the receiver. Therefore, no need to create new protocols.
Using these existing protocols makes the document more portable across multiple
platforms, more easily debugged and easier to understand.

5.Parsing and processing

It shares the same parsing and processing requirements as SGML and HTML.

6.Separation of data and presentation

We can keep the data and presentation in separate different files. Therefore, more no.
of presentation can be added for a single xml document.

7.Loosely coupled technology

It is a loosely coupled technology. This allows for changes in the presentation,


process and data layers without affecting the other layers.

8.XML Makes the Data More Available

(i) Since XML is independent of hardware, software and application, XML can make our
data more available and useful.

(ii) Different applications can access our data, not only in HTML pages, but also from
XML data sources.

(iii) With XML, our data can be available to all kinds of "reading machines" such as
Handheld computers, voice machines, news feeds, etc, and make it more available for
blind people, or people with other disabilities.

9.Simplifies platform changes

Upgrading to new systems (hardware or software platforms), is always very time


consuming. Large amounts of data must be converted and incompatible data is often lost.

XML data is stored in text format. This makes it easier to expand or upgrade to new
operating systems, new applications, or new browsers, without losing data.

10.Creates new internet languages

A lot of new Internet languages are created with XML.


Here are some examples:

• XHTML the latest version of HTML


• WSDL for describing available web services
• WAP and WML as markup languages for handheld devices
• RSS languages for news feeds
• RDF and OWL for describing resources and ontology
• SMIL for describing multimedia for the web
*********************************************************************
Advantages of XML over HTML

HTML XML
HTML was designed to display data, with XML was designed to transport and store
focus on how data looks. data, with focus on what data is.
Data and presentation resides in the same Data and presentation can be reside in a
document separate file
It uses predefined tags It uses own tags
Since it uses predefined tags, the browser Since it uses own tags, browser will not
understands the meaning of the tag. understand. It needs supporting technology
like SOAP to present the data
It is Case insensitive It is Case Sensitive
It is Well defined language It is a Meta language
It is not validated It is validated using DTD and Xml Schema

Drawbacks of XML

• XML documents occupy more space when compared with flatfiles/DB.


• Lacks Security.
• Parser loads the entire XML document into memory before processing.

XML document
It contains
➢ Markup tags(<,>)
➢ Actual Data
➢ Delimiter -> Character which differentiate the tags from actual data.
➢ Entity Reference(&lt; &gt; &apos; &amp; &quot;)

XML Document Structure


➢ XML Declaration
➢ Document Type Declaration
➢ Elements
➢ Attributes
➢ Character Data
➢ Entity References
➢ PI (Processing Instructions)
➢ CDATA Section
➢ Comments
➢ Whitespaces

XML Declaration

First line of the XML file


Syntax:
<?xml version = “1.0” encoding = “UTF-8” standalone = “ “?>
version-> “1.0” indicates the version
encoding -> indicates character encoding that the document uses like UTF-8, UTF-10,
etc.
standalone -> It has either yes or no value.
yes indicates Internal DTD is used.
no indicates External DTD is used.

Document Type Declaration


Syntax for External dtd:
<!DOCTYPE name SYSTEM “file.dtd”>
Syntax for Internal dtd:
<!DOCTYPE name SYSTEM
[
Internal DTD coding goes here
]
?>
It gives name to a XML content and provides a mean to validate it either by
including or specifying a link to DTD.

Elements
➢ Matched pair of tags or single self closing tag e.g. <br/> It is empty element.
➢ Empty element is an element without any content and it is suffixed by /.
➢ Elements contain nested tag, text or mixture of both.
➢ Rules of Naming Elements
• Should start with a letter.
• Space not allowed.
• Better to avoid - , . , ;
• Should not start with the word “xml”.
➢ Elements are extensible
Element content may be extended without any modification in the
application.
Attributes
➢ It is used to provide additional information to the elements.
➢ It is a name value pair that is specified in the start tag.
➢ Attribure must be quoted.

Entity Reference

➢ It provides a mean to indicate the xml processing application that a special string
is to follow that will be replaces with a literal value.
➢ Entity references should start with & and end with ;

Processing Instruction(PI)

It provide information to the application as to how the content should be


processed.

Syntax:
<?Instruction options?>

Instruction indicates what instruction it contains and options is any options

Example:
<?xml version=” “ encoding=” “ standalone=” “?>
<?xml-stylesheet type=”text/css” href=”book.css”?>

CDATA Section

➢ CDATA – Character Data


➢ It is a block of text where the user is free of give any kind of text.

Syntax:
<![CDATA [any text]]>
Example:
<Element>
<![CDATA[
<?xml version= “ “ encoding=” “ standalone= “ “?>
]]>
</Element>

Comment
Syntax:
<!- -
Any comments
- ->
WhiteSpaces
It includes Space, Tab, New line etc. In xml whitespace can be preserved by
setting a built in variable
xml:space=Yes/No

Rules for Writing XML Document

➢ XML documents form a tree structure.


➢ Elements must have a closing tag.
➢ XML tags are case sensitive.
➢ XML elements must be properly nested.
➢ XML document must have root element.
➢ Attribute value must be quoted.

Well Formed XML Document

Xml Document which follows with correct syntax is well formed xml document.

Validate XML Document


It is well formed xml document which also conforms the rules of DTD of
Schema.

XML Namespace
➢ XML is an open standard. XML authors are free to create whatever elements an
attribute they wish. So multiple xml document with the same element an attribute
possible. To avoid this namespaces are used.
➢ Namespaces provide a mean to avoid such name collision. Namespaces are
nothing but adding : delimiter prefix to differentiate the element and attributes.
Declaring Namespace
There are two types
• Default
• Explicit
➢ Namespaces can be declared by using the attribute xmlns with the root element.
➢ Namespace can be a simple text or a URL.
Default Declaration
<customer xmlns=”c”>
<name>
<address>
</customer>
Explicit Declaration
<c:customer xmlns:c=”c”>
Scope of Namespace
➢ All the child element inherits the parent’s namespace
➢ The child can also override by specifying a new space on a particular child
element.
Document Type Definition (DTD)
XML document

<?xml version=”1.0”?>
<book>
<title> xml book </title>
<author> Peterson </author>
</book>

XML

Sender Receiver

DTD
Sender uses the Receiver uses the
DTD to prepare DTD to check the
a valid XML <!ELEMENT book(title)> validity of incoming
document <!ELEMENT title(#PCDATA)> XML
Document Ty Declaration :

➢ It provides a way for describing and documenting the structure that makes up an
xml document.
➢ It allows the author to define the set of rules for an xml document to make it valid.

A document type declaration is placed in the XML document’s prolog section.


The syntax is

<!DOCTYPE name of the document type


[ elements specifications] >
The document type declaration starts with <!DOCTYPE and ends with >.

Within square bracket, we can specify the allowed elements in the xml document.

Example:

<!DOCTYPE inventory [
<!ELEMENT book (title)>
<!!ELEMENT title (#PCDATA)>]

The Document type declaration can be either a


1. internal subset (or)
2. external subset.

Internal subset
It is a DTD which resides within a single xml document. In internal subset, the
declaration of DTD is done within the xml document.
Syntax:
<!DOCTYPE rootelement
[
______
]>
External subset
The external subsets physically present in a different file . The external subset
ends with the extension .dtd. We have to utilize the keyword “SYSTEM", when we are
using the external subset.
Syntax:
<!DOCTYPE rootelement SYSTEM “file.dtd”>
Part of DTD

It contains
➢ Element Declaration
➢ Attribute list declaration
➢ Entity Declaration
➢ Comment
➢ Parameter entity declaration
➢ Directives
➢ Notations Declaration

Element type declarations:

Elements are the primary building block used in XML documents. The syntax of
element declaration is

<! ELEMENT name of the element or generic identifier (content specification)>

Generic identifier:

It is used to identify the name of the element.


Content specification:

Content specification , specifies the element’s allowed content . For example, if


the content specification is “#PCDATA”, the element must contain parsable character
data.
Example for DTD:

<?xml version=”1.0”?>
<!DOCTYPE inventory [
<!ELEMENT book (title)>
<!!ELEMENT title (#PCDATA)>]
<?xml version=”1.0”?>
<book>
<title> xml book </title>
<author> Peterson </author>
</book>

Sequences ,Pipe characters and occurrences indicators:

1.Sequence:
DTD allows the document author to define the order and frequency of child
elements. The comma(,) specifies the order in which the elements must occur.

Example:
<!ELEMENT classroom(teacher,student)>

2.pipe character:
The pipe character is used to specifies the choices.
Example:

<!ELEMENT dessert (icecream | pastry ) >

The above example shows that an dessert element can contain either icecream
or pastry.

3.occurrence indicators:
An element’s frequency ( no. of occurrences ) is specified by using either the
plus(+), asterisk(*), question mark(?).

Occurrence Indicators Description


Plus sign(+) An element can appear any no. of times, but
must appear at least once.
Eg: <!ELEMENT album (song)+>

Asterisk(*) An elemnent is optional and if used, the


element can appear any no.of times
Eg: <!ELEMENT library (book)*>

Question Mark(?) An element is optional and if used the


element can appear only once.
Eg: <!ELEMENT seat (person)?>
Different types of Content specification:

Three types of content specification is available for non-element content.

1. EMPTY 2. Mixed content 3. ANY

Occurrence Indicators Description


EMPTY: An element can contain empty elements.
Eg: <!ELEMENT oven EMPTY>

Mixed content: An element can contain any combination of


elements and PCDATA.
Eg: <!ELEMENT Mymessage (#PCDATA
| message)*>

ANY An element can contain any content

Atribute Declarations:

An attribute declaration specifies an attribute list for an element by using the ATTLIST
attribute list declaration.The syntax is

<!ATTLIST elementname attributename type defaultbehavior defaultvalue>

type -> Type of attribute


default behavior -> compulsory/optional
default value -> any default value

Types
• CDATA -> Character Content
• Enumerated -> any one from set of values (val1|val2)
• Tokenized -> Takes any one of 8 tokens.
ID,IDREF, IDREFS, ENTITY, ENTITIES, NMTOKEN, NMTOKENS,
NOTATION

Default Behavior
• #REQUIRED -> Attribute is compulsory.
• #IMPLIED -> Attribute is optional
• #FIXED -> Attribute value is fixed and cant be changed.

Default value
Here we can assign any default value for the attribute.

Eg: <!ATTLIST book title CDATA #REQUIRED>


Here book is the name of the element, title is the attribute of book. CDATA is
nothing but character data, therefore the title can contain any parsable character data .
#REQUIRED implies that it is must to specify the value of title attribute.There are some
other default attribute values are available in DTD.They are

Entity Declaration

Syntax:
<!ENTITY entityname SYSTEM “entity content”>
Internal Entity
Syntax: <!ENTITY cpy “copyright200”>
In this content resides in the same file.
External Entity
Syntax: <!ENTITY cpy SYSTEM “sample.xml”>

How to refer an Entity


&cpy;
The parser will replace all the entity names by its content. It is used to store the
frequently used data.

Parameter Entity
Entity which can be used only inside DTD.
Syntax:
<!ENTITY %entityname “content”>
Reference -> %name;
Eg:
<!ENTITY %p “#PCDATA”>

<!ELEMENT title %p;>


Drawbacks of DTD
➢ It follows non XML syntax
➢ It doesn’t support any data type(only support string).
➢ It doesn’t support namespace.
➢ It can refer only one DTD at a time.
➢ It can’t be extended.
Example
Internal DTD
<?xml version="1.0"?>
<!DOCTYPE note [
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend</body>
</note>
External DTD
<?xml version="1.0"?>
<!DOCTYPE note SYSTEM "note.dtd">
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
Note.dtd
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
Schemas
Similar to DTD, schema also useful for defining the structure of an XML document.
DTD vs.Schema:
The Schema supports broad range of data types , where as the DTD considers everything
as a string.It eliminates the need for hand-coded data checking of XML data fields.
Eg: <quantity> 5</quantity>
If the element is validated against DTD, it is not at all a error. Because , DTD
Concentrate on XML document’s structure , not its element content. With XML schema,
element quantity’s data can be described as numeric.
<?xml version=”1.0”?>
<book>
<title> xml book </title>
<author> Peterson </author>
</book>

XML

Sender Receiver

Schema

<?xml version =”1.0”>


<Schema xmlns=”urn:schema-microsoft-com:xml-data”>
<ElemnentType name=”book” model=”closed”
content=”eltOnly” order=”many”>
<ElementType>

<ElemnentType name=”title” model=”closed”


content=”mixed” order=”many”>
<ElementType>
</Schema>

The purpose of an XML Schema :

An XML Schema:

• defines elements that can appear in a document


• defines attributes that can appear in a document
• defines which elements are child elements
• defines the order of child elements
• defines the number of child elements
• defines whether an element is empty or can include text
• defines data types for elements and attributes
• defines default and fixed values for elements and attributes
XML Schemas are the Successors of DTDs

The reasons are:

• XML Schemas are extensible to future additions.


• XML Schemas are richer and more powerful than DTDs
• XML Schemas are written in XML
• XML Schemas support data types
• XML Schemas support namespaces
Schema Datatypes:

Data type Description


Boolean 0 or 1
Char Single character
String A series of characters
Float A real number
Int A whole number
Date A date formatted as YYYY-MM-DD
Time A time formateed as HH-MM-SS
Id Text that uniquely identifies an element or
attribute
Idref A reference to an id
Enumuration A series of values from which only one
may be chosen.

XML Schemas Support Data Types

One of the greatest strength of XML Schemas is the support for data types.

With support for data types:

• It is easier to describe allowable document content


• It is easier to validate the correctness of data
• It is easier to work with data from a database
• It is easier to define restrictions on data
• It is easier to define data formats

XML Schemas use XML Syntax

Another great strength about XML Schemas is that they are written in XML.

Some benefits of that XML Schemas are written in XML:

• There is no need to learn a new language


• We can use our XML editor to edit the Schema files
• We can use our XML parser to parse the Schema files
• We can manipulate the Schema with the XML DOM
• We can transform the Schema with XSLT
• It is easier to convert data between different data types

The Structure of schema Element

<?xml version="1.0"?>

<xs:schema> [The <schema> element is the root element of every XML Schema ]

...
Declaration of elements, attributes and its complex structure along with data types
...
</xs:schema>

Two types of schema element:


1. Simple element
2. Complex element
(1). Simple element:

A simple element is an XML element that can contain only text. It cannot
contain any other elements or attributes.

(i) Defining a Simple Element

The syntax for defining a simple element is:

<xsd:element name=” “ [type = “ “ default= “ “ fixed= “ “ minOccurs=” “

maxOccurs= “ “ mixed=” “ nillable=” “]/>

name -> name of elements to be declared.

type -> specify the data type of the element content.

default -> specify the default content for the element[this is for simpletype only]

fixed -> specify the fixed content to the element [this is for simpletype only]

minOccurs -> specify the minimum no. of times that the element can appear in the
document.
maxOccurs -> specify the maximum no. of times that the element can appear in the
document.

mixed -> It takes the value true of false

True indicates that the element can contain both text and element and false
indicates that the element should contain any one text or element.

nillable -> It takes the value true of false

True allows the element to take null value. False doesn’t allow the element to
take null value.

Example 1 for string , integer and date data types.:

The following are the elements of XML documents and its schema definitions.The data
type of elements are string, integer and date.

Elements of xml document:

<lastname>Refsnes</lastname>
<age>36</age>
<dateborn>1970-03-27</dateborn>

Schema definition of above xml document:

<xs:element name="lastname"
type="xs:string"/>
<xs:element name="age" type="xs:integer"/>
<xs:element name="dateborn" type="xs:date"/>

Example 2 Default and Fixed Values for Simple Elements

Simple elements may have a default value OR a fixed value specified.

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"/>

A fixed value is also automatically assigned to the element, and we cannot specify
another value.
In the following example the fixed value is "red":

<xs:element name="color" type="xs:string" fixed="red"/>

Example 3 for defining an Attribute

The syntax for defining an attribute is:

<attribute name=” “ [type=” “ default=” “ fixed=” “ use=” “]/>

name -> name of the attribute to be declared

type -> specify the data type of attribute

default -> specify the default content for6 the attribute

fixed -> specify the fixed content to the attributes.

use -> indicates the default behavior of the attributes.

• Optional – may
• Required – must
• Prohibited – must not

Example:

Here is an XML element with an attribute:

<book title="web service"> Peterson </book>

And here is the corresponding attribute definition:

<xs:attribute name="title" type="xs:string"/>

Examples for Restrictions on Content

When an XML element or attribute has a data type defined, it puts restrictions on the
element's or attribute's content.

(i) Restrictions on Values


The following example defines an element called "age" with a restriction. The value of
age cannot be lower than 0 or greater than 120:

<xs:element name="age">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="120"/>
</xs:restriction>
</xs:simpleType>
</xs:element>

(ii) Restrictions on a Set of Values

To limit the content of an XML element to a set of acceptable values, we would use the
enumeration constraint.

The example below defines an element called "car" with a restriction. The only
acceptable values are: Audi, Golf, BMW:

<xs:element name="car">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Audi"/>
<xs:enumeration value="Golf"/>
<xs:enumeration value="BMW"/>
</xs:restriction>
</xs:simpleType>
</xs:element>

The example above could also have been written like this:

<xs:element name="car" type="carType"/>

<xs:simpleType name="carType">
<xs:restriction base="xs:string">http://start.ubuntu.com/9.10/
<xs:enumeration value="Audi"/>
<xs:enumeration value="Golf"/>
<xs:enumeration value="BMW"/>
</xs:restriction>
</xs:simpleType>
(iii) Restrictions on a Series of Values

To limit the content of an XML element to define a series of numbers or letters that can
be used, we would use the pattern constraint.

The example below defines an element called "letter" with a restriction. The only
acceptable value is ONE of the LOWERCASE letters from a to z:

<xs:element name="letter">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-z]"/>
</xs:restriction>
</xs:simpleType>
</xs:element>

The only acceptable value is THREE of the UPPERCASE letters from a to z:

<xs:element name="initials">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[A-Z][A-Z][A-Z]"/>
</xs:restriction>
</xs:simpleType>
</xs:element>

The next example also defines an element called "initials" with a restriction. The only
acceptable value is THREE of the LOWERCASE OR UPPERCASE letters from a to z:

<xs:element name="initials">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-zA-Z][a-zA-Z][a-zA-Z]"/>
</xs:restriction>
</xs:simpleType>
</xs:element>

The next example defines an element called "choice" with a restriction. The only
acceptable value is ONE of the following letters: x, y, OR z:

<xs:element name="choice">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[xyz]"/>
</xs:restriction>
</xs:simpleType>
</xs:element>

The next example defines an element called "prodid" with a restriction. The only
acceptable value is FIVE digits in a sequence, and each digit must be in a range from 0 to
9:

<xs:element name="prodid">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:pattern value="[0-9][0-9][0-9][0-9][0-9]"/>
</xs:restriction>
</xs:simpleType>
</xs:element>

Complex Element

A complex element is an XML element that contains other elements and/or attributes.

There are four kinds of complex elements:

• empty elements
• elements that contain only other elements
• elements that contain only text
• elements that contain both other elements and text

Example :
The following XML element, "employee", contains only other elements:
<employee>
<firstname>John</firstname>
<lastname>Smith</lastname>
</employee>
We can define a complex element in an XML Schema in two different ways:
1. The "employee" element can be declared directly by naming the element, like this:
<xs:element name="employee">
<xs:complexType>
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>

2. The "employee" element can have a type attribute that refers to the name of the
complex type to use:
<xs:element name="employee" type="personinfo"/>

<xs:complexType name="personinfo">
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:sequence>
</xs:complexType>

************************************************************************

XSLT: (Extensible Style Sheet Language Transformation)

XSLT is an XML–based language used to transform XML documents into other


formats such as HTML for web display, WML for display on WAP devices, XML
dialects for B2B data transfer or a plain text.

The XSLT processor reads both an XML document and XSLT document that
defines how to transform the XML. The processor has the capability to read the XML
source document and rearrange and reassemble it in a variety of ways. It can add new
text and tags.

XSL(Stylesheet)
➢ XSL Stylesheet which converts xml source tree to xml result tree or output tree.
➢ Transformation means
• Add/Delete elements or attributes.
• Rearrange/sort elements.
• Formatting options

Structure of XSL Stylesheet

Syntax
<xsl:stylesheet version=1.0 xmlns:xsl=”http://www.w3.org/1999/XSLtransform”>
Or
<xsl:transform version=1.0 xmlns:xsl=”http://www.w3.org/1999/XSLtransform”>
<xsl:template>
.
.
.
</xsl:template>
</xsl:stylesheet>
➢ The root element that declare a document to be an xsl stylesheet by xsl:stylesheet
or xsl:transform
➢ To get access to the xslt element, attribute and features we must declare xml
namespace at the top of the document.
➢ An xsl stylesheet consists of one or more set of rules that are called templates.
➢ Template have one attributes “match”. It is used to associate the template with an
xml document.
/ →template for whole document.
Eg:
<xsl:template match=”/bookstore/book”>
</xsl:template>

1)<xsl:value-of>
Syntax
<xsl:value-of select=”catalog/cd/title”/>

Which element This is XPath.


Value
2)<xsl:for-each>
Syntax
<xsl:for-each>
.
.
</xsl:for-each>
Eg:
<xsl:for-each select=”catalog/cd”>
<tr>
<td><xsl:value-of select=”title”/></td>
<td><xsl:value-of select=”artist”/></td?
</tr>
</xsl:for-each>

3)Predicate
By adding the condition in the xpath given in select attribute.
Eg:
<xsl:for-each select=”catalog/cd[price &gt; 10]

4)<xsl:sort select= “ “/>


It is used to sort.

5)<xsl:if test= “ “
------
------
</xsl:if>
test → It is used to give test expression.
Eg:
<xsl:for-each select=”catalog/cd”>
<xsl:if test=”artist=”Bob””>
<tr><td><xsl:value-of select=”title”/></td>
<td><xsl:value-of select=”artist”/></td>
</tr>
</xsl:if>
</xsl:for-each>

6)<xsl:choose><xsl:when><xsl:otherwise>
Syntax:
<xsl:choose>
<xsl:when test=” “
----
----
</xsl:when>
<xsl:when test=” “>
.
.
.
<xsl:otherwise>---------</xsl:otherwise>
</xsl:choose>

Example Program for XSL


<?xml version=”1.0” encoding=”ISO-8839.1”?>
<xsl:stylesheet version=”1.0” xmlns:xsl=”-------“>
<xsl:template match=”/”>
<html>
<body>
<h2>My CD Collection</h2>
<table border =”1”>
<tr bgcolor =”#9acdd32”
<th>Title</th><th>Artist</th></tr>
<xsl:for-each select=”catalog/cd”>
<tr>
<td><xsl:value-of select=”title”/></td>
<xsl:choose>
<xsl:when test=”price &gt; 100>”
<td bgcolor=”#ffooff”>
<xsl:value-of select=”artist”/></td>
</xsl:when>
<xsl:when test=”price &gt; 9”>
<td bgcolor=”#cccccc”>
<xsl:value-of select=”artist”/></td>
</xsl:when>
</xsl:otherwise>
<td><xsl:value-of select=”artist”/></td>
</xsl:otherwise>
</xsl:Choose>
</tr></xsl:for-each>
</xsl:stylesheet>

What is Web Service?


It is one of the Distributed computing technologies.
Web Services are loose coupled contracted components that communicate via the
XML based interfaces.
Loose coupled means the Web services and the programs that invoke them can be
changed independently of each other.
Contracted means that a Web Service’s behavior, its input and output parameters,
and how to bind to it are publicly available.
A component is encapsulated code, which means that the implementation of each
component is hidden from outside the component.
Advantage of Web Services
➢ It is platform and language independent.
➢ Web services use HTTP for transmitting messages.
➢ Since it uses XML they have human readable text based format which is firewall
friendly and self describing.
Limitation of other Technology (RMI,DCOM,CORBA etc)
➢ Tightly coupled technology.
➢ Since they use different protocol we can not call a DCOM server from RMI
client.
➢ All these technologies are typical for intranet application.
➢ Although DOM and CORBA provide cross platform interoperability they are too
complex and need large amount of manual integration work
➢ Since they use binary wired protocol like IIOP and RPC they are human readable
and often has difficulty moving through firewall.

Difference between WebSite and WebService


Web Site Web Services
It is for User It is for the Software
User can access web site directly User can not access web service directly.
How it works

Where can I find web service


1 Server A

U can find it in server B Discovery


2 Service
Client

3. How can I invoke a web?


Service Server B
4.Give the prototype inWSDL Web
5.SOAP Request Service
6 SOAP Response

***********************************************************************
The service-oriented architecture (SOA)

The web service is a component that can be described, published ,located and invoked
over the Internet.
The term service-oriented means that the architecture is described and organized to
support web services’ dynamic, automated description,publication discovery and use.
The SOA organizes web services into three basic roles:
1.The service provider
2.The service requester
3.The service registry
Service Provider

Publish Service
Bind
Description Client

Service registry Service Requester


Find

Fig. Web Services roles and relationships

1. The service providers publish their services to a service registry.


2.The service requesters can find the desired web services by searching for their
descriptions at the service registry
3. Once the requester locates the desired service, its client binds with the service at the
service provider and then invokes the service.
Responsibility of SOA:
• The SOA is responsible for describing and organizing the mechanisms and
practices for each of these actions.
• The SOA, is also responsible for how services can be combined into larger
services

Вам также может понравиться