SERVICE ORIENTED ARCHITECTURE
& WEB SERVICES
ITC 3013
[Link]
Dept. of ICT, Faculty of Technology
University of Sri Jayewardenepura
XML TOPIC 2
1
XML – EXTENSIBLE MARKUP LANGUAGE
XML stands for eXtensible Markup Language.
XML is a markup language much like HTML.
XML was designed to carry data, not to display data.
XML tags are not predefined. You must define your own
tags.
XML is designed to be self-descriptive.
XML is extensible.
XML is designed to be both human and machine-readable.
XML is a W3C Recommendation. It is an open standard.
2
WHY WAS XML INTRODUCED (AT THE
TIME…)?
HTML has become a complex language (latest version has
more than 100 different tags).
To improve HTML to support growing technologies, more
tags were needed, but, it would add weight to the
language.
Some devices (in the early days..) did not have enough
processing power to handle such a complex language.
Therefore better structuring required.
To address the shortcomings, XML was introduced.
3
XML VS HTML
XML is not a replacement for HTML.
Both XML and HTML is based on SGML.
(Standard Generalized Markup Language)
XML and HTML were designed with different goals:
▪ XML was designed to transport and store data, with focus on what data
is
▪ HTML was designed to display data, with focus on how data looks
▪ HTML is about displaying information, while XML is about carrying
information
4
HOW CAN XML BE USED?
XML is used in many aspects of web development, often to
simplify data storage and sharing.
▪ XML Separates Data from HTML. XML does not carry any
information about how to be displayed.
▪ XML Simplifies Data Sharing
▪ XML Simplifies Data Transport
▪ XML Simplifies Platform Changes
▪ XML Makes Your Data More Available
5
XML IS USED TO CREATE NEW INTERNET
LANGUAGES
There are lot of new Internet languages are created with
XML. Here are some examples:
▪ XHTML
▪ WSDL for describing available web services
▪ 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
6
INTERNET LANGUAGES & PROTOCOL
XHTML - This is a cleaner and stricter version of HTML 4.01.
WSDL - Web Service Definition Language
WAP - Wireless Application Protocol
( It uses the Wireless Markup Language )
WML – Wireless Markup Language
RSS - Rich Site Summary - Really Simple Syndication
RDF - Resource Description Framework
OWL - Web Ontology Language
SMIL - Synchronized Multimedia Integration Language
7
XML TREE
XML documents form a tree structure that starts at the root
and branches to the leaves.
XML documents use a self-describing and simple syntax.
8
XML DOCUMENTS DON’T RUN OR
‘EXECUTE’
It needs only any editor like notepad and any browser. It no needs compile
and run xml code its a markup language.
Displaying XML with XSLT
Use XSLT to transform XML into HTML, before it is displayed in a browser. XSLT is
far more sophisticated than CSS. With XSLT you can add/remove elements and
attributes to or from the output file. You can also rearrange and sort elements,
perform tests and make decisions about which elements to hide and display, and a
lot more.
Source : XML and XSLT ([Link])
9
XML VIEW
Display as XML file
Display as Note
10
XML TREE
The first line is the XML prolog. It defines the XML version
1.0 and the encoding used.
The next line describes the root element of the document:
<student>
The next 3 lines describe the 3 child elements of the root:
<idno>1001</idno>
<name>Bruce</name>
<age>20</age>
And finally the last line defines the end of the root element:
</student>
11
Source: [Link]
12
XML DOCUMENTS FORM A TREE
STRUCTURE
XML documents must contain a root element.
This element is "the parent" of all other elements.
The elements in an XML document form a document tree.
The tree starts at the root and branches to the lowest level
of the tree.
All elements can have sub elements (child elements):
13
XML DOCUMENTS FORM A TREE
STRUCTURE
The terms parent, child, and sibling are used to describe
the relationships between elements. Parent elements have
children. Children on the same level are called siblings.
14
XML DOCUMENT: EXAMPLE
15
XML SYNTAX RULES
Tag names are case sensitive.
In XML, the tag <Letter> is different from the tag <letter>.
Opening and closing tags must be written with the same case.
16
XML SYNTAX RULES
Every opening tag must have a corresponding closing tag
(unless it is as an empty tag).
In XML, it is illegal to omit the closing tag. All elements must have a
closing tag.
The XML prolog does not have a closing tag. The prolog is not a
part of the XML document.
17
XML SYNTAX RULES
All XML elements must be properly nested.
In XML, all elements must be properly nested within each other.
In the example above, "Properly nested" simply means that
since the <entry> element is opened inside the <phone>
element, it must be closed inside the <phone> element.
18
XML SYNTAX RULES
XML Documents Must Have a Root Element
XML documents must contain one element that is the parent of all
other elements. This element is called the root element.
19
XML SYNTAX RULES
XML Attribute Values Must be Quoted
XML elements can have attributes in name/value pairs just like in
HTML.
In XML, the attribute values must always be quoted.
Study the two XML documents below. The first one is incorrect, the
second is correct:
20
ENTITY REFERENCES
Some characters have special meaning in XML.
For an example, if a character like “<” is placed inside an XML
element, it will be interpreted as a start of a new element.
21
ENTITY REFERENCES
The following will generate an XML error:
To avoid the error in the example above, the “<” character
with an entity reference.
22
XML SYNTAX
The syntax for writing comments in XML is similar to that of
HTML.
HTML truncates multiple white-space characters to one
single white-space.
With XML, the white-space in a document is not truncated
(white-space is preserved). 23
XML SYNTAX RULES
XML documents that conform to the syntax rules above are
said to be "Well Formed" XML documents.
XML has 3 fundamental building blocks:
Elements
Attributes
Values
24
XML ELEMENTS
An XML document contains XML elements.
An XML element is everything from (including) the element's
start tag to (including) the element's end tag.
An element can contain:
other elements
text
attributes
or a mix of all of the above...
An element is used to describe or contain a piece of
Information
Elements usually consist of two tags: an opening tag and a
closing tag 25
XML ELEMENTS
In the example:
• <title>, <author>,
<year>, and <price>
have text content because
they contain text.
• <bookstore> and <book>
have element contents,
because they contain
elements.
• <book> has an attribute
(category="children").
26
EMPTY XML ELEMENTS
An empty XML element is an element without content.
Empty elements can have attributes.
An alternative syntax can be used for empty elements.
<book/>
This is called a self-closing tag.
27
XML NAMING RULES
XML elements must follow these naming rules, element
names:
Are case sensitive.
Must start with a letter or an underscore.
Cannot start with the letters xml (or XML, or Xml etc.).
Can contain letters, digits, hyphens, underscores, and periods.
Cannot contain spaces.
Any name can be used, no words are reserved, except xml.
28
XML NAMING STYLES
There are no naming styles defined for XML elements.
Following are some of the common naming styles used:
29
XML ATTRIBUTES
XML elements can have attributes, just like HTML.
Attributes provide additional information about an
element.
Attributes often provide information that is not a part of
the data. In the example below, the file type is irrelevant
to the data, but can be important to the software that
wants to manipulate the element.
30
XML ATTRIBUTES
XML attributes must be quoted. Either single or double
quotes can be used.
For a person’s gender, the person element can be written
like this:
<person sex="female"> or <person sex='female'>
If the attribute value itself contains double quotes you can
use single quotes, like in this example:
<person name='Floyd "Money" Mayweather'>
or you can use entity references:
<person name='Floyd "Money" Mayweather'>
31
XML ATTRIBUTES
In the first example below, idno is an attribute. In the
second example, idno is an element. Both provide the same
information.
32
XML ATTRIBUTES: WHEN TO AVOID?
Some of the problems with using attributes are:
Attributes cannot contain multiple values (elements can)
Attributes cannot contain tree structures (elements can)
Attributes are not easily expandable (for future changes)
Attributes are difficult to read and maintain. Use elements
for data. Use attributes for information that is not relevant
to the data.
33
XML ATTRIBUTES: FOR METADATA
Sometimes ID references are assigned to elements. These IDs can
be used to identify XML elements in much the same way as the id
attribute in HTML.
In the example:
• The id attributes are for
identifying the different notes.
• It is not a part of the note
itself.
• Usually, metadata (data
about data) should be stored
as attributes, and the data
itself should be stored as
elements.
34
XML NAMESPACES
XML Namespaces provide a method to avoid element 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.
35
XML NAMESPACES
The following XML carries HTML table information:
<table>
<tr>
<td>Apples</td>
<td>Bananas</td>
</tr>
</table>
This XML carries information about a table (a piece of furniture):
<table>
<name>African Coffee
Table</name>
<width>80</width>
<length>120</length>
</table> 36
NAME CONFLICT ISSUE AND
SOLUTION
In the previous example, if the two XML parts were added
together, there would be a name conflict. This issue can be
solved with namespaces.
<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> 37
XML
NAMESPACES: <root xmlns:h="[Link]
R/html4/"
XMLNS ATTRIBUTE
xmlns:f="[Link]
rnitureDetails">
When using prefixes, like <h:table>
<h:tr>
in the previous example, <h:td>Apples</h:td>
a namespace must be <h:td>Bananas</h:td>
</h:tr>
defined. </h:table>
<f:table>
<f:name>African Coffee
Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table>
</root>
38
Q&A
39