Академический Документы
Профессиональный Документы
Культура Документы
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.
It shares the same parsing and processing requirements as SGML and HTML.
We can keep the data and presentation in separate different files. Therefore, more no.
of presentation can be added for a single xml document.
(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.
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.
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 document
It contains
➢ Markup tags(<,>)
➢ Actual Data
➢ Delimiter -> Character which differentiate the tags from actual data.
➢ Entity Reference(< > ' & ")
XML Declaration
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)
Syntax:
<?Instruction options?>
Example:
<?xml version=” “ encoding=” “ standalone=” “?>
<?xml-stylesheet type=”text/css” href=”book.css”?>
CDATA Section
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
Xml Document which follows with correct syntax is well formed xml document.
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.
Within square bracket, we can specify the allowed elements in the xml document.
Example:
<!DOCTYPE inventory [
<!ELEMENT book (title)>
<!!ELEMENT title (#PCDATA)>]
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
Elements are the primary building block used in XML documents. The syntax of
element declaration is
Generic identifier:
<?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>
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:
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(?).
Atribute Declarations:
An attribute declaration specifies an attribute list for an element by using the ATTLIST
attribute list declaration.The syntax is
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.
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”>
Parameter Entity
Entity which can be used only inside DTD.
Syntax:
<!ENTITY %entityname “content”>
Reference -> %name;
Eg:
<!ENTITY %p “#PCDATA”>
XML
Sender Receiver
Schema
An XML Schema:
One of the greatest strength of XML Schemas is the support for data types.
Another great strength about XML Schemas is that they are written in XML.
<?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>
A simple element is an XML element that can contain only text. It cannot
contain any other elements or attributes.
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.
True indicates that the element can contain both text and element and false
indicates that the element should contain any one text or element.
True allows the element to take null value. False doesn’t allow the element to
take null value.
The following are the elements of XML documents and its schema definitions.The data
type of elements are string, integer and date.
<lastname>Refsnes</lastname>
<age>36</age>
<dateborn>1970-03-27</dateborn>
<xs:element name="lastname"
type="xs:string"/>
<xs:element name="age" type="xs:integer"/>
<xs:element name="dateborn" type="xs:date"/>
A default value is automatically assigned to the element when no other value is specified.
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":
• Optional – may
• Required – must
• Prohibited – must not
Example:
When an XML element or attribute has a data type defined, it puts restrictions on the
element's or attribute's content.
<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>
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: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>
<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.
• 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>
************************************************************************
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
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”/>
3)Predicate
By adding the condition in the xpath given in select attribute.
Eg:
<xsl:for-each select=”catalog/cd[price > 10]
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>
***********************************************************************
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