[go: up one dir, main page]

0% found this document useful (0 votes)
24 views27 pages

XML Extensible Markup Language

Uploaded by

moh913118
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)
24 views27 pages

XML Extensible Markup Language

Uploaded by

moh913118
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/ 27

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.

• Structure: the organization and inter-relationship of the


components

• Presentation: how a document looks and what processes are


applied to it.

3
Separating these things means…
• Content can be re-used

• Structure can be formally validated

• Presentation can be customized for


 Different media
 Different audiences

• The information can be uncoupled from its processing

4
What is metadata?
• Data about data

• Data associated with objects which relieves their potential users of


having to have full advance knowledge of their existence or
characteristics.

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.

• An HTML page encodes information in a form easily processed by


humans.

• HTML lacks a structure that facilitates information processing.

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?

• Product info in HTML:


 What is the price of the item?
 What category of item is it?

• If you want to publish information in a form that software clients can


process it
 You need to produce pages in which the structure is explicit for software to
exploit.

• That’s what XML does.

9
The different between HTML and XML?
• HTML was designed to display data and to focus on how data
looks

• XML was designed to structure data and to focus on what data is

10
XML looks like a bit like HTML
• Like HTML , XML makes use of tags (words bracketed by ‘<’ .. ‘>’).

• HTML is a specific markup language that contains a fixed set of


elements and attributes.
 The tags used to HTML documents and the structure of HTML documents
are predefined (I.e. <p>, <h1>,…)

• 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

name email phone birthday

first last year month day

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.

• Preorder traversals are usually used for getting information out of


the tree.

16
Steps of creating an XML file
• Discover (or establish) the structure of your data.
 Use DTD or XML schema

• Build the XML file that holds the data.

• Apply a formatting style to the xml file.

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 [

• Then comes a list of all elements and attributes contained in the


XML file, including the document element

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

You might also like