0% found this document useful (0 votes)
9 views32 pages

Itec102 Midterm L1

This document provides an introduction to XML, explaining its significance in IT systems, data distribution, and its role in web development. It covers the basics of XML, including its structure, syntax rules, and key differences from HTML, emphasizing XML's extensibility and ability to separate data from presentation. Additionally, it outlines important XML standards and applications across various industries.

Uploaded by

Hans Galang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views32 pages

Itec102 Midterm L1

This document provides an introduction to XML, explaining its significance in IT systems, data distribution, and its role in web development. It covers the basics of XML, including its structure, syntax rules, and key differences from HTML, emphasizing XML's extensibility and ability to separate data from presentation. Additionally, it outlines important XML standards and applications across various industries.

Uploaded by

Hans Galang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

Introduction to

XML
ITEC102 – Integrative Programming and Technologies
Introduction to XML
Why Study XML?
➢ XML plays an important role in many different IT

systems.
➢ XML is often used for distributing data over the

Internet.
➢ It is important (for all types of software

developers!) to have a good understanding of


XML.
Introduction to XML

What You Will Learn

✓ What is XML?
✓ How does XML work?
✓ How can I use XML?
✓ What can I use XML for?
Introduction to XML

Important XML Standards


➢ XML AJAX
➢ XML DOM
➢ XML XPath
➢ XML XSLT
➢ XML XQuery
➢ XML DTD
➢ XML Schema
➢ XML Services
Introduction to XML
• XML is a software- and hardware-independent tool for storing and
transporting data.

What is XML?

➢ XML stands for eXtensible Markup Language


➢ XML is a markup language much like HTML
➢ XML was designed to store and transport data
➢ XML was designed to be self-descriptive
➢ XML is a W3C Recommendation
XML Does Not DO Anything
Maybe it is a little hard to understand, but XML does not DO anything.
This note is a note to Tove from Jani, stored as XML:
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
The XML above is quite self-descriptive:

1. It has sender information


2. It has receiver information
3. It has a heading
4. It has a message body
But still, the XML above does not DO anything. XML is just information wrapped in tags.
Someone must write a piece of software to send, receive,
store, or display it:
The Difference Between
XML and HTML
✓ XML and HTML were designed with different goals:
✓ XML was designed to carry data - with focus on what
data is
✓ HTML was designed to display data - with focus on how
data looks
✓ XML tags are not predefined like HTML tags are
XML Does Not Use Predefined Tags
❖ The XML language has no predefined tags.
❖ The tags in the example above (like <to> and <from>) are
not defined in any XML standard. These tags are
"invented" by the author of the XML document.
❖ HTML works with predefined tags like <p>, <h1>,
<table>, etc.
❖ With XML, the author must define both the tags and the
document structure.
XML is Extensible
❖ Most XML applications will work as expected even if new
data is added (or removed).
❖ Imagine an application designed to display the original
version of note.xml (<to> <from> <heading> <body>).
❖ Then imagine a newer version of note.xml with added
<date> and <hour> elements, and a removed <heading>.
❖ The way XML is constructed, older version of the
application can still work
XML Simplifies Things

✓XML simplifies data sharing


✓XML simplifies data transport
✓XML simplifies platform changes
✓XML simplifies data availability

XML is a W3C Recommendation


➢ XML became a W3C Recommendation as early as in February 1998.
How Can XML
be Used?
XML is used in many aspects of web XML is often used to separate data from
development. presentation.
XML is used in XML is often used
many aspects of to separate data
web from
development. presentation.
XML Separates Data from Presentation

XML does not carry any information about how to be displayed.

The same XML data can be used in many different presentation


scenarios.

Because of this, with XML, there is a full separation between data and
presentation.

XML is Often a Complement to HTML

In many HTML applications, XML is used to store or transport data, while


HTML is used to format and display the same data.
XML Separates Data from HTML

When displaying data in HTML, you should not have to edit the HTML file
when the data changes.

With XML, the data can be stored in separate XML files.

With a few lines of JavaScript code, you can read an XML file and update
the data content of any HTML page.
<?xml version="1.0" encoding="UTF-8"?>
<bookstore>

<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>

<book category="children">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>

<book category="web">
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>

<book category="web" cover="paperback">


<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>

</bookstore>
Transaction Data

Thousands of XML formats exist, in many different industries, to


describe day-to-day data transactions:

➢ Stocks and Shares


➢ Financial transactions
➢ Medical data
➢ Mathematical data
➢ Scientific measurements
➢ News information
➢ Weather services
The XML Tree Structure
An Example XML Document
The image above represents books in this XML:
<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="children">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="web">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
XML Tree Structure

➢ XML documents are formed as element


trees.
➢ An XML tree starts at a root element and
branches from the root to child elements.
➢ All elements can have sub elements (child
elements):

<root>
<child>
<subchild>.....</subchild>
</child>
</root>
XML Tree Structure

➢ The terms parent, child, and sibling are


used to describe the relationships
between elements.
➢ Parents have children. Children have
parents. Siblings are children on the
same level (brothers and sisters).
➢ All elements can have text content
(Harry Potter) and attributes
(category="cooking").
Self – Describing Syntax

➢ XML uses a much self – describing


syntax.
➢ A prolog defines the XML version and
the character encoding
➢ The <book> elements have 4 child
elements: <title>, <author>, <year>,
<price>.

➢ The next line ends the book element::


➢ The next line is the root element of the
document:

➢ The next line starts a <book> element:


Menu
Menu

XML Syntax
Rules
The syntax rules of
XML are very simple
and logical. The rules
are easy to learn, and
easy to use.
XML Documents Must Have a Root
Element
XML documents must
contain
one root element that
is the parent of all
other elements:
The XML Prolog
This line is called the
XML prolog:
The XML prolog is optional. If it
exists, it must come first in the
document.
XML documents can contain
international characters, like
Norwegian øæå or French êèé.
To avoid errors, you should specify
the encoding used, or save your
XML files as UTF-8.
UTF-8 is the default character
encoding for XML documents.
UTF-8 is also the default encoding
for HTML5, CSS, JavaScript, PHP,
and SQL.
➢ All XML Elements Must
Have a Closing Tag

➢ XML Tags are Case


Sensitive

➢ XML Elements Must be


Properly Nested

➢ XML Attribute Values


Must Always be Quoted
Comments in XML

The syntax for writing comments in


XML is similar to that of HTML:
White-space is Preserved
in XML
XML does not truncate multiple
white-spaces (HTML truncates
multiple white-spaces to one
single white-space):
XML Stores New Line as
LF
➢ Windows applications store a
new line as: carriage return and
line feed (CR+LF).
➢ Unix and Mac OSX use LF.
➢ Old Mac systems use CR.
➢ XML stores a new line as LF.

XML documents that conform to the syntax rules


above are said to be "Well Formed" XML
documents.

You might also like