CSC 330 E-Commerce
Teacher
Ahmed Mumtaz Mustehsan
GM-IT CIIT Islamabad
Virtual Campus, CIIT
COMSATS Institute of Information Technology
T2-Lecture-4
eXtensible Markup Language (XML)
Part - II
For Lecture Material/Slides Thanks to: www.w3schools.com
Objectives
XML Elements
are extensible
XML Attributes
XML Namespaces
XML Encoding
Viewing
3
T2-Lecture-4
XML Files
Ahmed Mumtaz Mustehsan
www.w3schools.com
XML Elements are Extensible
XML elements can be extended to carry more information.
Look at the following XML example:
◦ <note>
<to>mumtaz</to>
<from>tariq</from>
<body> Don't forget to attend party on weekend!</body>
</note>
Let's imagine that we created an application that extracted
the <to>, <from>, and <body> elements from the XML
document to produce this output: Message
To: Mumtaz
From: Tariq
Don't forget to attend party on
weekend!
4
T2-Lecture-3
Ahmed Mumtaz Mustehsan
www.w3schools.com
XML Elements are Extensible…
Imagine
that the author of the XML document added some
extra information to it:
Message
To: Mumtaz
<note>
From: Tariq
<date>2008-01-10</date>
Don't forget to attend party on
<to>Mumtaz</to>
weekend!
<from>Tariq</from>
<heading>Reminder</heading>
<body> Don't forget to attend party on weekend!</body>
</note>
Should
the application break or crash?
No. The application should still be able to find the <to>,
<from>, and <body> elements in the XML document and
produce the same output.
One of the beauty of XML, is that it can be extended
without breaking applications.
5
T2-Lecture-3
Ahmed Mumtaz Mustehsan
www.w3schools.com
XML Attributes
XML Attributes
In
HTML, attributes provide additional information
about elements:

height="42">
XML elements can have attributes, just like HTML.
Attributes often provide information that is not a part
of the data but it is information about data.
Example
<file type="gif">computer.gif</file>
The file type is irrelevant to the data, but can be
important to the software that wants to manipulate the
element:
7
T2-Lecture-4
Ahmed Mumtaz Mustehsan
www.w3schools.com
XML Attributes Must be Quoted
Attribute
values must always be quoted. Either
single or double quotes can be used.
Example:
For a person's sex, the person element can be
written like this:
or like this:
8
T2-Lecture-4
Ahmed Mumtaz Mustehsan
www.w3schools.com
XML Attributes Must be Quoted
If
the attribute value itself contains double quotes we
can use single quotes.
Example:
<University head = ‘ Rector “COMSATS" Institute'>
or you can use character entities:
Institute'>
9
T2-Lecture-4
Ahmed Mumtaz Mustehsan
www.w3schools.com
XML Elements vs. Attributes
Example-1: