XML Extensible Markup Language
XML Extensible Markup Language
1
Document exchange
Word Processor Spreadsheet
XML
Web Browser
2
Components of a document
• Content: the components (words, images, etc). Which make up a
document.
3
Separating these things means…
• Content can be re-used
4
What is metadata?
• Data about data
5
What is XML?
• XML stands for EXtensible Markup Language
• It is called extensible because it is no a fixed format like HTML
• XML is set of rules for designing text formats that let you structure
data
• XML tags are not predefined. You must define your own tags
6
What does XML Look Like?
• It is only a text file and it doesn’t require you to have a particular
operating system or hardware.
<?xml version="1.0"?>
<Document>
<Greeting>
Welcome to XML
</Greeting>
<Message>
This is an XML document. Bet you're surprised.
</Message>
</document>
7
Why XML?
• XML makes the structure of the document explicit to computer
programs.
8
Example: It is hard to do the following
with HTML
• News in HTML:
What’s the headline of the story?
Who is the author?
9
The different between HTML and XML?
• HTML was designed to display data and to focus on how data
looks
10
XML looks like a bit like HTML
• Like HTML , XML makes use of tags (words bracketed by ‘<’ .. ‘>’).
• XML uses the tags only to delimit pieces of data , and leaves the
interpretation of the data completely to the application that reads it.
11
XML vs. HTML: Information Storage
• HTML
Information is stored in HTML in its final form
• XML:
Information stored in XML can be presented in a variety of ways for
different audiences and scenarios , since the data and display are separate.
12
XML Rules
• Tags are enclosed in angle brackets.
• Tags come in pairs with start-tags and end-tags.
• Tags must be properly nested.
<name><email>…</name></email> is not allowed.
<name><email>…</email><name> is.
13
More XML Rules
• Tags are case sensitive.
<address> is not the same as <Address>
• XML in any combination of cases is not allowed as part of a tag.
• Tags may not contain ‘<‘ or ‘&’.
• Documents must have a single root tag that begins the document.
14
XML Files are Trees
address
15
XML Trees
• An XML document has a single root node.
• The tree is a general ordered tree.
A parent node may have any number of children.
Child nodes are ordered, and may have siblings.
16
Steps of creating an XML file
• Discover (or establish) the structure of your data.
Use DTD or XML schema
17
Document Type Definitions
18
Document type definitions
• DTDs (Document Type Definitions) contain a list of element , tags,
attributes and entity references contained in an XML document and
describes their relationships to each other.
• Simply, DTD
Specifies a list of tags
Defines the relationships between these tags .
19
Document Type Definitions
• A DTD describes the tree structure of a document and something
about its data.
• There are two data types, PCDATA and CDATA.
PCDATA is parsed character data.
CDATA is character data, used about text data not be parsed.
• A DTD determines how many times a node may appear, and how
child nodes are ordered.
20
DTD for address Example
<!ELEMENT address (name, email, phone, birthday)>
<!ELEMENT name (first, last)>
<!ELEMENT first (#PCDATA)>
<!ELEMENT last (#PCDATA)>
<!ELEMENT email (#PCDATA)>
<!ELEMENT phone (#PCDATA)>
<!ELEMENT birthday (year, month, day)>
<!ELEMENT year (#PCDATA)>
<!ELEMENT month (#PCDATA)>
<!ELEMENT day (#PCDATA)>
21
Structure of a DTD
• A DTD always starts with <! DOCTYPE and always ends with ]>
• Directly after the <! DOCTYPE comes the name of the document
element followed by a [
22
Example of DTD
<!DOCTYPE note
[
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
23
XML: Example of DTD
<!DOCTYPE employees [
<!ELEMENT employees (name,email,tel,fax)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT email (#PCDATA)>
<!ELEMENT tel (#PCDATA)>
<!ELEMENT fax (#PCDATA)>
]>
24
Example: XML Structure
<employees>
<name>Karim</name>
<email>karim@yahoo.com</email>
<tel>00202352</tel>
<fax>00202536</fax>
</ employees>
25
Where do I get a DTD?
• Industry announcements
• Some recent examples
Chemical Markup Language(chemical modelling)
Math Markup Language
Etc.
26
Assignment
• What is XML Schema Definition (XSD)
• Compare it with DTD
27