Week 6 XML
Week 6 XML
EXTENSIBLE MARKUP
LANGUAGE
IMPORTANT RESOURCE
W3Schools Tutorials
•XML Tutorial •XML Schema Tutorial
•Recommended parts: •Recommended parts:
•XML Introduction •XSD Introduction
•XML How to Use
•XML Tree
•XSD How To
•XSD <schema>
Optional tutorials that
•XML Syntax
•XML Elements
•XSD Elements
•XSD Attributes
cover XML and XML
•XML Attributes
•XML Namespaces
•XSD Complex Elements
•XSD Elements Only
Schemas.
•XML Display •XSD Text-Only Elements
•XML Validator •XSD Indicators Great resource if you
•XML Schema •XSD String Data Types
•XSD Date and Time Data Types need extra help with XML.
•XSD Numeric Data Types
•XSD Miscellaneous Data Types
3
COMPUTER
COMPUTER
COMPUTER
COMPUTER
COMPUTER
10100110 →B
» Binary numbers can represent text, images, videos, etc.
8
COMPUTER
Now you want to deliver (transmit) those ones and zeros to all your friends.
How?
Connection.
9
COMPUTER
Now you want to deliver (transmit) those ones and zeros to all your friends.
How?
MARKUP LANGUAGES
Annotations to text
» instructions on how text is to be displayed/used.
Types:
» Presentational
» Procedural
» Descriptive
⋄ GML/SGML
⋄ HTML/XHTML
⋄ XML
MESSAGE & DATA EXCHANGE
11
TECHNOLOGIES
• Telephone
• Paper (Fax, Postal mail)
• Email
• Electronic Data Interchange (EDI)
• eXtensible Markup Language (XML)
12
XML
So…
XML
DATA -
From one computer
To another computer
14
XML
DATA -
From one computer
To another computer
15
XML
A method (mechanism) to copy (upload) large amounts
of data into a database.
DATA
16
XML
17
XML: EXAMPLE
Add a list of all of your friends:
- their names, ages and hobby
XML: EXAMPLE
Add a list of all of your friends:
- their names, ages and hobby
XML: EXAMPLE
Add a list of all of your friends:
- their names, ages and hobby
Way to much
data to enter
by hand!
20
XML
Have each
student send
their list by
Email:
21
XML
Have each
student send
their list by
Email:
22
XML
Each student sends data formatted differently!
Have each
student send
their list by
Email:
23
XML
Each student sends data formatted differently!
Have each
student send
their list by
Email:
No standardized
format used.
Still need to reinput
in database by hand!
24
XML
XML:
Provides a
standardized
format for data.
25
XML
XML:
Computer readable.
Can automate
import!
26
XML
XML
EASY:
data
- enclosed (encased) by tags
XML
EASY:
data
Joe Bloggs
29
XML
EASY:
data
Joe Bloggs
XML
EASY:
data
Joe Bloggs
XML
<tag1>
<tag2>
<tag3>Hope Ferdebest</tag3>
<tag4>English</tag4>
<tag5>2020</tag5>
</tag2>
</tag1>
32
XML
XML
XML
END TAGS
forward slash/
35
XML
XML
<tag1>
<tag2>
<tag3>Hope Ferdebest</tag3> tag3, tag4 and tag5
<tag4>English</tag4> are simple tags
<tag5>2020</tag5>
</tag2>
</tag1>
SIMPLE TAGS
37
XML
<tag1>
<tag2>
<tag3>Hope Ferdebest</tag3> tag1 and tag2 are
<tag4>English</tag4> complex tags
<tag5>2020</tag5>
</tag2>
</tag1>
COMPLEX TAGS
38
XML
Tags - complex: allows “grouping” of data
<tag1>
<tag2>
<tag3>Hope Ferdebest</tag3>
<tag4>English</tag4> GROUP #1
<tag5>2020</tag5>
</tag2>
<tag2>
<tag3>Isma Braineful</tag3>
<tag4>Math</tag4> GROUP #2
<tag5>2019</tag5>
</tag2>
</tag1>
39
XML
Tags - complex: allows “grouping” of data
<tag1>
<tag2>
<tag3>Hope Ferdebest</tag3>
<tag4>English</tag4> GROUP #1
<tag5>2020</tag5>
</tag2> MAJOR
<tag2> GROUP
<tag3>Isma Braineful</tag3>
<tag4>Math</tag4> GROUP #2
<tag5>2019</tag5>
</tag2>
</tag1>
40
XML
Tags - complex: grouping tags have the same (repeating) labels
<tag1>
<tag2>
<tag3>Hope Ferdebest</tag3>
<tag4>English</tag4> GROUP #1
<tag5>2020</tag5>
</tag2> MAJOR
<tag2> GROUP
<tag3>Isma Braineful</tag3>
<tag4>Math</tag4> GROUP #2
<tag5>2019</tag5>
</tag2>
</tag1>
41
XML
Tags - simple: grouping tags have the same (repeating) labels
<tag1>
<tag2>
<tag3>Hope Ferdebest</tag3>
<tag4>English</tag4> GROUP #1
<tag5>2020</tag5>
</tag2> MAJOR
<tag2> GROUP
<tag3>Isma Braineful</tag3>
<tag4>Math</tag4> GROUP #2
<tag5>2019</tag5>
</tag2>
</tag1>
42
XML
Tags - They should be meaningful to the data context
<course>
<student>
<name>Hope Ferdebest</name>
<major>English</major>
<year>2020</year> Tags should have
</student > descriptive labels
<student > (not just tag1, tag2, etc.)
<name>Isma Braineful</name>
<major>Math</major>
<year>2018</year>
</student >
</course>
43
XML
⋄ names(s)
⋄ age(s)
⋄ hobbies(s)
45
⋄ Billy
⋄ 31
DATA
⋄ Avengers
⋄ DandD
46
Notepad++ (https://notepad-plus-plus.org/)
48
DO THE
TAGS LAST!
49
GOAL <?xml version="1.0"?>
<FriendList>
<Friend>
<name>Billy</name>
<age>31</age>
<hobbies>
<hobby>Avengers</hobby>
<hobby>DandD</hobby>
</hobbies>
</Friend>
<Friend>
Billy 31 Cosplay, Avengers, DandD <name>Idris</name>
<age>27</age>
Idris 27 Dr. Who <hobbies>
<hobby>Dr. Who</hobby>
Jordan 19 Star Wars, My Little Pony </hobbies>
</Friend>
<Friend>
<name>Jordan</name>
<age>19</age>
<hobbies>
<hobby>Star Wars</hobby>
<hobby>My Little Pony</hobby>
</hobbies>
</Friend>
</FriendList>
50
STEP 1: BREAK IT DOWN
Idris GROUPINGS!
27
Dr. Who
• One data point per line
Jordan
• Break it down into groups
19 separated by spaces
Star Wars • Keep data in group together
My Little Pony
• One piece of data on each line
STEP 2: 53
IDENTIFY
GROUPINGS Billy
31
cosplay
Avengers
DandD
Idris
27
Dr. Who
Jordan
19
Star Wars
My Little Pony
STEP 2: 54
IDENTIFY
GROUPINGS Billy
31
cosplay
Avengers
DandD
Idris
27
LOGICAL UNITS
Dr. Who
- Have come commonality
Jordan
19
Star Wars GROUPINGS!
My Little Pony
STEP 2: 55
IDENTIFY
GROUPINGS Billy
31
cosplay
Avengers
DandD
Idris
27
LOGICAL UNITS
Dr. Who
- Have come commonality
Jordan
19
Star Wars GROUPINGS!
My Little Pony
STEP 2: 56
IDENTIFY
GROUPINGS Billy
31
cosplay
Avengers
DandD
Idris
27
LOGICAL UNITS
Dr. Who
- Have come commonality
Jordan
19
Star Wars GROUPINGS!
My Little Pony
STEP 2: 57
IDENTIFY
GROUPINGS Billy
31
cosplay
Avengers
DandD
Idris
27
LOGICAL UNITS
Dr. Who
- Have come commonality
Jordan
19
Star Wars GROUPINGS!
My Little Pony
STEP 2: 58
IDENTIFY
GROUPINGS Billy
31
cosplay
Avengers
DandD
Idris
27 Give descriptive
Dr. Who
names to the
groupings
Jordan
19
Star Wars
My Little Pony
STEP 2: 59
FriendList
IDENTIFY
GROUPINGS Billy
31
cosplay
Avengers
DandD
Idris
27 Give descriptive
Dr. Who
names to the
groupings
Jordan
19
Star Wars
My Little Pony
STEP 2: 60
FriendList
IDENTIFY
GROUPINGS Billy
31
cosplay
Avengers
DandD Friend
Idris
27 Give descriptive
Dr. Who
names to the
groupings
Jordan
19 Friend
Star Wars
My Little Pony
Friend
STEP 2: 61
FriendList
IDENTIFY
GROUPINGS Billy
31 Hobbies
cosplay
Avengers
DandD Friend
Idris
27 Give descriptive
Dr. Who
Hobbies names to the
groupings
Jordan
19 Friend
Star Wars
My Little Pony
Hobbies
Friend
STEP 3: 62
FriendList
NAME THE
DATA Billy
31 Hobbies
cosplay
Avengers
DandD Friend
Idris
27
Dr. Who
Jordan
Hobbies
Give descriptive
Friend
19
Star Wars names to each
My Little Pony
Idris
27
Dr. Who
name
Hobbies
Jordan
Give descriptive
Friend
19
Star Wars
My Little Pony
names to each
name
Hobbies data element
Friend
STEP 3: 64
FriendList
NAME THE
DATA name
Billy
31 Hobbies
cosplay
Avengers
DandD Friend
Idris
27
Dr. Who
name
Jordan
Hobbies
Give descriptive
Friend
19
Star Wars names to each
My Little Pony
name
Hobbies data element
Friend
STEP 3: 65
FriendList
NAME THE
DATA name
Billy
31 Hobbies
age cosplay
Avengers
DandD Friend
Idris
27
Dr. Who
name
age
Jordan
Hobbies
Give descriptive
Friend
19
Star Wars names to each
My Little Pony
name
age
Hobbies data element
Friend
STEP 3: 66
FriendList
NAME THE
DATA name
Billy
31 Hobbies
age cosplay
hobby Avengers
hobby
DandD Friend
hobby
Idris
27
Dr. Who
name
age
hobby Jordan
Hobbies
Give descriptive
Friend
19
Star Wars names to each
My Little Pony
name
age
Hobbies data element
hobby
hobby Friend
STEP 3: 67
FriendList
NAME THE
DATA name
Billy
31 Hobbies
age cosplay
hobby Avengers
hobby
DandD Friend
hobby
AND DATA
<FriendList>
Billy
name
31 Hobbies
age cosplay
hobby Avengers
hobby
DandD Friend
hobby
Idris
27
Dr. Who
name
age Hobbies
hobby Jordan
19 Friend
Star Wars
My Little Pony
name
age
Hobbies
hobby
hobby Friend
STEP 5: FriendList
74
AND DATA
<FriendList>
Billy <Friend>
name
31 Hobbies
age cosplay
hobby Avengers
hobby
DandD Friend
hobby
Idris
27
Dr. Who
name
age Hobbies
hobby Jordan
19 Friend
Star Wars
My Little Pony
name
age
Hobbies
hobby
hobby Friend
STEP 5: FriendList
75
AND DATA
<FriendList>
Billy <Friend>
name
31 Hobbies <name>Billy</name>
age cosplay
hobby Avengers
hobby
DandD Friend
hobby
Idris
27
Dr. Who
name
age Hobbies
hobby Jordan
19 Friend
Star Wars
My Little Pony
name
age
Hobbies
hobby
hobby Friend
STEP 5: FriendList
76
AND DATA
<FriendList>
Billy <Friend>
name
31 Hobbies <name>Billy</name>
age cosplay <age>31</age>
hobby Avengers
hobby
DandD Friend
hobby
Idris
27
Dr. Who
name
age Hobbies
hobby Jordan
19 Friend
Star Wars
My Little Pony
name
age
Hobbies
hobby
hobby Friend
STEP 5: FriendList
77
AND DATA
<FriendList>
Billy <Friend>
name
31 Hobbies <name>Billy</name>
age cosplay <age>31</age>
hobby Avengers <hobbies>
hobby
DandD Friend
hobby
Idris
27
Dr. Who
name
age Hobbies
hobby Jordan
19 Friend
Star Wars
My Little Pony
name
age
Hobbies
hobby
hobby Friend
STEP 5: FriendList
78
AND DATA
<FriendList>
Billy <Friend>
name
31 Hobbies <name>Billy</name>
age cosplay <age>31</age>
hobby Avengers <hobbies>
hobby
DandD Friend <hobby>cosplay</hobby>
hobby
Idris
27
Dr. Who
name
age Hobbies
hobby Jordan
19 Friend
Star Wars
My Little Pony
name
age
Hobbies
hobby
hobby Friend
STEP 5: FriendList
79
AND DATA
<FriendList>
Billy <Friend>
name
31 Hobbies <name>Billy</name>
age cosplay <age>31</age>
hobby Avengers <hobbies>
hobby
DandD Friend <hobby>cosplay</hobby>
<hobby>Avengers</hobby>
hobby
Idris
27
Dr. Who
name
age Hobbies
hobby Jordan
19 Friend
Star Wars
My Little Pony
name
age
Hobbies
hobby
hobby Friend
STEP 5: FriendList
80
AND DATA
<FriendList>
Billy <Friend>
name
31 Hobbies <name>Billy</name>
age cosplay <age>31</age>
hobby Avengers <hobbies>
hobby
DandD Friend <hobby>cosplay</hobby>
<hobby>Avengers</hobby>
hobby <hobby>DandD</hobby>
Idris
27
Dr. Who
name
age Hobbies
hobby Jordan
19 Friend
Star Wars
My Little Pony
name
age
Hobbies
hobby
hobby Friend
STEP 5: FriendList
81
AND DATA
<FriendList>
Billy <Friend>
name
31 Hobbies <name>Billy</name>
age cosplay <age>31</age>
hobby Avengers <hobbies>
hobby
DandD Friend <hobby>cosplay</hobby>
<hobby>Avengers</hobby>
hobby <hobby>DandD</hobby>
Idris </hobbies>
27
Dr. Who
name
age Hobbies
hobby Jordan
Friend
Important!
19
Star Wars
My Little Pony
name
age
Hobbies We must end each
hobby
hobby Friend grouping with an end
tag.
STEP 5: FriendList
82
AND DATA
<FriendList>
Billy <Friend>
name
31 Hobbies <name>Billy</name>
age cosplay <age>31</age>
hobby Avengers <hobbies>
hobby
DandD Friend <hobby>cosplay</hobby>
<hobby>Avengers</hobby>
hobby <hobby>DandD</hobby>
Idris </hobbies>
27 </Friend>
Dr. Who
name
age Hobbies
hobby Jordan
19 Friend
Star Wars
My Little Pony
name
age
Hobbies We must end each
hobby
hobby Friend grouping with an end
tag.
STEP 5: FriendList
83
AND DATA
<FriendList>
Billy <Friend>
name
31 Hobbies <name>Billy</name> One friend has
age cosplay <age>31</age>
hobby Avengers <hobbies> been input into
DandD Friend <hobby>cosplay</hobby>
hobby
<hobby>Avengers</hobby> the XML
hobby
Idris
<hobby>DandD</hobby>
</hobbies> document so
27
Dr. Who
</Friend>
far.
name
age Hobbies
hobby Jordan
19 Friend
Star Wars
My Little Pony
name
age
Hobbies
hobby
hobby Friend
STEP 5: FriendList
84
AND DATA
<FriendList>
Billy <Friend>
name
31 Hobbies <name>Billy</name>
age cosplay <age>31</age>
hobby Avengers <hobbies>
hobby
DandD Friend <hobby>cosplay</hobby>
<hobby>Avengers</hobby>
hobby <hobby>DandD</hobby>
Idris </hobbies>
27 </Friend>
Dr. Who <Friend>
name
age Hobbies
hobby Jordan
19 Friend
Star Wars
My Little Pony
name
age
Hobbies
hobby
hobby Friend
STEP 5: FriendList
85
AND DATA
<FriendList>
Billy <Friend>
name
31 Hobbies <name>Billy</name>
age cosplay <age>31</age>
hobby Avengers <hobbies>
hobby
DandD Friend <hobby>cosplay</hobby>
<hobby>Avengers</hobby>
hobby <hobby>DandD</hobby>
Idris </hobbies>
27 </Friend>
Dr. Who <Friend>
name
age Hobbies <name>Idris</name>
hobby Jordan
19 Friend
Star Wars
My Little Pony
name
age
Hobbies
hobby
hobby Friend
STEP 5: FriendList
86
AND DATA
<FriendList>
Billy <Friend>
name
31 Hobbies <name>Billy</name>
age cosplay <age>31</age>
hobby Avengers <hobbies>
hobby
DandD Friend <hobby>cosplay</hobby>
<hobby>Avengers</hobby>
hobby <hobby>DandD</hobby>
Idris </hobbies>
27 </Friend>
Dr. Who <Friend>
name
age Hobbies <name>Idris</name>
<age>27</age>
hobby Jordan
19 Friend
Star Wars
My Little Pony
name
age
Hobbies
hobby
hobby Friend
STEP 5: FriendList
87
AND DATA
<FriendList>
Billy <Friend>
name
31 Hobbies <name>Billy</name>
age cosplay <age>31</age>
hobby Avengers <hobbies>
hobby
DandD Friend <hobby>cosplay</hobby>
<hobby>Avengers</hobby>
hobby <hobby>DandD</hobby>
Idris </hobbies>
27 </Friend>
Dr. Who <Friend>
name
age Hobbies <name>Idris</name>
<age>27</age>
hobby Jordan <hobbies>
19 Friend
Star Wars
My Little Pony
name
age
Hobbies
hobby
hobby Friend
STEP 5: FriendList
88
AND DATA
<FriendList>
Billy <Friend>
name
31 Hobbies <name>Billy</name>
age cosplay <age>31</age>
hobby Avengers <hobbies>
hobby
DandD Friend <hobby>cosplay</hobby>
<hobby>Avengers</hobby>
hobby <hobby>DandD</hobby>
Idris </hobbies>
27 </Friend>
Dr. Who <Friend>
name
age Hobbies <name>Idris</name>
<age>27</age>
hobby Jordan <hobbies>
19 Friend <hobby>Dr. Who</hobby>
Star Wars
My Little Pony
name
age
Hobbies
hobby
hobby Friend
STEP 5: FriendList
89
AND DATA
<FriendList>
Billy <Friend>
name
31 Hobbies <name>Billy</name>
age cosplay <age>31</age>
hobby Avengers <hobbies>
hobby
DandD Friend <hobby>cosplay</hobby>
<hobby>Avengers</hobby>
hobby <hobby>DandD</hobby>
Idris </hobbies>
27 </Friend>
Dr. Who <Friend>
name
age Hobbies <name>Idris</name>
<age>27</age>
hobby Jordan <hobbies>
19 Friend <hobby>Dr. Who</hobby>
Star Wars </hobbies>
My Little Pony
name
age
Hobbies
hobby
hobby Friend
STEP 5: FriendList
90
AND DATA
<FriendList>
Billy <Friend>
name
31 Hobbies <name>Billy</name>
age cosplay <age>31</age>
hobby Avengers <hobbies>
hobby
DandD Friend <hobby>cosplay</hobby>
<hobby>Avengers</hobby>
hobby <hobby>DandD</hobby>
Idris </hobbies>
27 </Friend>
Dr. Who <Friend>
name
age Hobbies <name>Idris</name>
<age>27</age>
hobby Jordan <hobbies>
19 Friend <hobby>Dr. Who</hobby>
Star Wars </hobbies>
My Little Pony </Friend>
name
age
Hobbies
hobby
hobby Friend
STEP 5: FriendList
91
AND DATA
<FriendList>
Billy <Friend>
name
31 Hobbies <name>Billy</name>
age cosplay <age>31</age>
hobby Avengers <hobbies>
hobby
DandD Friend <hobby>cosplay</hobby>
<hobby>Avengers</hobby>
hobby <hobby>DandD</hobby>
Idris </hobbies>
name
27
Dr. Who
</Friend>
<Friend> 2nd friend has
age Hobbies <name>Idris</name>
<age>27</age> been input into
hobby Jordan
19 Friend
<hobbies>
<hobby>Dr. Who</hobby>
the XML
Star Wars
My Little Pony
</hobbies>
</Friend>
document.
name
age
Hobbies
hobby
hobby Friend
STEP 5: FriendList
92
AND DATA
<FriendList>
Billy <Friend>
name
31 Hobbies <name>Billy</name>
age cosplay <age>31</age>
hobby Avengers <hobbies>
hobby
DandD Friend <hobby>cosplay</hobby>
<hobby>Avengers</hobby>
hobby <hobby>DandD</hobby>
Idris </hobbies>
27 </Friend>
Dr. Who <Friend>
name
age Hobbies <name>Idris</name>
<age>27</age>
hobby Jordan <hobbies>
19 Friend <hobby>Dr. Who</hobby>
Star Wars </hobbies>
My Little Pony </Friend>
name <Friend>
age
Hobbies
hobby
hobby Friend
STEP 5: FriendList
93
AND DATA
<FriendList>
Billy <Friend>
name
31 Hobbies <name>Billy</name>
age cosplay <age>31</age>
hobby Avengers <hobbies>
hobby
DandD Friend <hobby>cosplay</hobby>
<hobby>Avengers</hobby>
hobby <hobby>DandD</hobby>
Idris </hobbies>
27 </Friend>
Dr. Who <Friend>
name
age Hobbies <name>Idris</name>
<age>27</age>
hobby Jordan <hobbies>
19 Friend <hobby>Dr. Who</hobby>
Star Wars </hobbies>
My Little Pony </Friend>
name <Friend>
age
Hobbies <name>Jordan</name>
hobby
hobby Friend
STEP 5: FriendList
94
AND DATA
<FriendList>
Billy <Friend>
name
31 Hobbies <name>Billy</name>
age cosplay <age>31</age>
hobby Avengers <hobbies>
hobby
DandD Friend <hobby>cosplay</hobby>
<hobby>Avengers</hobby>
hobby <hobby>DandD</hobby>
Idris </hobbies>
27 </Friend>
Dr. Who <Friend>
name
age Hobbies <name>Idris</name>
<age>27</age>
hobby Jordan <hobbies>
19 Friend <hobby>Dr. Who</hobby>
Star Wars </hobbies>
My Little Pony </Friend>
name <Friend>
age
Hobbies <name>Jordan</name>
<age>19</age>
hobby
hobby Friend
STEP 5: FriendList
95
AND DATA
<FriendList>
Billy <Friend>
name
31 Hobbies <name>Billy</name>
age cosplay <age>31</age>
hobby Avengers <hobbies>
hobby
DandD Friend <hobby>cosplay</hobby>
<hobby>Avengers</hobby>
hobby <hobby>DandD</hobby>
Idris </hobbies>
27 </Friend>
Dr. Who <Friend>
name
age Hobbies <name>Idris</name>
<age>27</age>
hobby Jordan <hobbies>
19 Friend <hobby>Dr. Who</hobby>
Star Wars </hobbies>
My Little Pony </Friend>
name <Friend>
age
Hobbies <name>Jordan</name>
<age>19</age>
hobby <hobbies>
hobby Friend <hobby>Star Wars</hobby>
<hobby>My Little Pony</hobby>
</hobbies>
STEP 5: FriendList
96
AND DATA
<FriendList>
Billy <Friend>
name
31 Hobbies <name>Billy</name>
age cosplay <age>31</age>
hobby Avengers <hobbies>
hobby
DandD Friend <hobby>cosplay</hobby>
<hobby>Avengers</hobby>
hobby <hobby>DandD</hobby>
Idris </hobbies>
27 </Friend>
Dr. Who <Friend>
name
age Hobbies <name>Idris</name>
<age>27</age>
hobby Jordan <hobbies>
19 Friend <hobby>Dr. Who</hobby>
Star Wars </hobbies>
My Little Pony </Friend>
name <Friend>
age
Hobbies <name>Jordan</name>
<age>19</age>
hobby <hobbies>
hobby Friend <hobby>Star Wars</hobby>
<hobby>My Little Pony</hobby>
</hobbies>
</Friend>
STEP 5: FriendList
97
AND DATA
<FriendList>
Billy <Friend>
name
31 Hobbies <name>Billy</name>
age cosplay <age>31</age>
hobby Avengers <hobbies>
hobby
DandD Friend <hobby>cosplay</hobby>
<hobby>Avengers</hobby>
hobby <hobby>DandD</hobby>
Idris </hobbies>
27 </Friend>
Dr. Who <Friend>
name
age Hobbies <name>Idris</name>
<age>27</age>
hobby Jordan <hobbies>
19 Friend <hobby>Dr. Who</hobby>
Star Wars </hobbies>
My Little Pony </Friend>
name
Hobbies
<Friend> Last friend has
age <name>Jordan</name>
hobby
<age>19</age>
<hobbies>
been input into
hobby Friend the XML
<hobby>Star Wars</hobby>
<hobby>My Little Pony</hobby>
</hobbies> document.
</Friend>
STEP 5: FriendList
98
AND DATA
<FriendList>
Billy <Friend>
name
31 Hobbies <name>Billy</name>
age cosplay <age>31</age>
hobby Avengers <hobbies>
hobby
DandD Friend <hobby>cosplay</hobby>
<hobby>Avengers</hobby>
hobby <hobby>DandD</hobby>
Idris </hobbies>
27 </Friend>
Dr. Who <Friend>
name
age Hobbies <name>Idris</name>
<age>27</age>
hobby Jordan <hobbies>
19 Friend <hobby>Dr. Who</hobby>
Star Wars </hobbies>
My Little Pony </Friend>
name <Friend>
age
Hobbies <name>Jordan</name>
<age>19</age>
hobby <hobbies>
hobby Friend <hobby>Star Wars</hobby>
<hobby>My Little Pony</hobby>
</hobbies>
</Friend>
?
STEP 5: FriendList
99
AND DATA
<FriendList>
Billy <Friend>
name
31 Hobbies <name>Billy</name>
age cosplay <age>31</age>
hobby Avengers <hobbies>
hobby
DandD Friend <hobby>cosplay</hobby>
<hobby>Avengers</hobby>
hobby <hobby>DandD</hobby>
Idris </hobbies>
27 </Friend>
Dr. Who <Friend>
name
age Hobbies <name>Idris</name>
<age>27</age>
hobby Jordan <hobbies>
19 Friend <hobby>Dr. Who</hobby>
Star Wars </hobbies>
My Little Pony </Friend>
name <Friend>
age
Hobbies <name>Jordan</name>
<age>19</age>
hobby <hobbies>
hobby Friend <hobby>Star Wars</hobby> Don’t forget to
<hobby>My Little Pony</hobby>
</hobbies>
</Friend>
end the root
? element!
STEP 5: FriendList
100
AND DATA
<FriendList>
Billy <Friend>
name
31 Hobbies <name>Billy</name>
age cosplay <age>31</age>
hobby Avengers <hobbies>
hobby
DandD Friend <hobby>cosplay</hobby>
<hobby>Avengers</hobby>
hobby <hobby>DandD</hobby>
Idris </hobbies>
27 </Friend>
Dr. Who <Friend>
name
age Hobbies <name>Idris</name>
<age>27</age>
hobby Jordan <hobbies>
19 Friend <hobby>Dr. Who</hobby>
Star Wars </hobbies>
My Little Pony </Friend>
name <Friend>
age
Hobbies <name>Jordan</name>
<age>19</age>
hobby <hobbies>
hobby Friend <hobby>Star Wars</hobby> Don’t forget to
<hobby>My Little Pony</hobby>
</hobbies>
</Friend>
end the root
</FriendList> element!
STEP 5: FriendList
101
AND DATA
<FriendList>
Billy <Friend>
name
31 Hobbies <name>Billy</name>
age cosplay <age>31</age>
hobby Avengers <hobbies>
hobby
DandD Friend <hobby>cosplay</hobby>
<hobby>Avengers</hobby>
hobby <hobby>DandD</hobby>
Idris </hobbies>
27 </Friend>
Dr. Who <Friend>
name
age Hobbies <name>Idris</name>
<age>27</age>
hobby Jordan <hobbies>
19 Friend <hobby>Dr. Who</hobby>
Star Wars </hobbies>
My Little Pony </Friend>
name <Friend>
age
Hobbies <name>Jordan</name>
<age>19</age>
hobby <hobbies>
hobby Friend <hobby>Star Wars</hobby> Don’t forget to
<hobby>My Little Pony</hobby>
</hobbies>
</Friend>
end the root
</FriendList> element!
FriendList
102
- The RULES
<?xml version="1.0"?>
- everything Billy
is either <FriendList>
<Friend>
name
a tagage
or data
31
cosplay
Hobbies <name>Billy</name>
<age>31</age>
hobby Avengers <hobbies>
Friend
- tags
hobbyare case sensitive
DandD <hobby>cosplay</hobby>
<hobby>Avengers</hobby>
hobby <hobby>DandD</hobby>
Idris </hobbies>
- every start27tag </Friend>
MUST
name have
Dr. Who <Friend>
age Hobbies <name>Idris</name>
a hobby
matching end
Jordan
tag <age>27</age>
<hobbies>
19 Friend <hobby>Dr. Who</hobby>
Star Wars </hobbies>
- tags can not overlap
My Little Pony </Friend>
name
- proper nesting
<Friend>
age
Hobbies <name>Jordan</name>
<age>19</age>
hobby <hobbies>
- XML Documents can
hobby Friend <hobby>Star Wars</hobby>
… to import into
<hobbies>
<hobby>cosplay</hobby>
a database…
<hobby>Avengers</hobby>
<hobby>DandD</hobby>
</hobbies>
</Friend>
<Friend>
<name>Idris</name>
<age>27</age>
<hobbies>
<hobby>Dr. Who</hobby>
</hobbies>
</Friend>
<Friend>
<name>Jordan</name>
<age>19</age>
<hobbies>
<hobby>Star Wars</hobby>
<hobby>My Little Pony</hobby>
</hobbies>
</Friend>
… into a computer file … </FriendList>
107
REMEMBER!
DO THE
TAGS LAST!
QUICK REVIEW
108
<?xml version="1.0"?>
<FriendList>
<Friend>
<name>Billy</name> Top Level Grouping
<age>31</age>
<hobbies>
<hobby>Avengers</hobby>
<hobby>DandD</hobby>
</hobbies>
</Friend>
<Friend>
<name>Idris</name> Top Level Grouping
<age>27</age>
<hobbies>
<hobby>Dr. Who</hobby>
</hobbies>
</Friend>
<Friend>
<name>Jordan</name> Top Level Grouping
<age>19</age>
<hobbies>
<hobby>Star Wars</hobby>
<hobby>My Little Pony</hobby>
</hobbies>
</Friend>
</FriendList>
QUICK REVIEW
109
<?xml version="1.0"?>
<FriendList>
<Friend>
<name>Billy</name>
<age>31</age>
<hobbies>
<hobby>Avengers</hobby>
Inner Level Grouping
<hobby>DandD</hobby>
</hobbies>
</Friend>
<Friend>
<name>Idris</name>
<age>27</age>
<hobbies>
<hobby>Dr. Who</hobby> Inner Level Grouping
</hobbies>
</Friend>
<Friend>
<name>Jordan</name>
<age>19</age>
<hobbies>
<hobby>Star Wars</hobby> Inner Level Grouping
<hobby>My Little Pony</hobby>
</hobbies>
</Friend>
</FriendList>
QUICK REVIEW
110
<?xml version="1.0"?>
<FriendList>
<Friend>
<name>Billy</name>
<age>31</age>
<hobbies>
<hobby>Avengers</hobby>
<hobby>DandD</hobby>
</hobbies> Data ‘Simple’ Groupings
</Friend>
<Friend>
<name>Idris</name>
<age>27</age>
<hobbies>
<hobby>Dr. Who</hobby>
</hobbies>
</Friend>
<Friend>
<name>Jordan</name>
<age>19</age>
<hobbies>
<hobby>Star Wars</hobby>
<hobby>My Little Pony</hobby>
</hobbies>
</Friend>
</FriendList>
111
QUICK REVIEW
<?xml version="1.0"?>
<Friend>
<name>Billy</name>
<age>31</age>
<hobbies>
<hobby>cosplay</hobby>
<hobby>D and D</hobby>
</hobbies>
</Friend>
</FriendList>
112
QUICK REVIEW
<?xml version="1.0"?>
<FriendList> Root
- and ‘end tag’ for Root
<Friend>
<name>Billy</name>
<age>31</age>
<hobbies>
<hobby>cosplay</hobby>
<hobby>D and D</hobby>
</hobbies>
</Friend>
</FriendList>
113
QUICK REVIEW
<?xml version="1.0"?>
<FriendList>
Top Level Grouping
<Friend> … and end tag for grouping
<name>Billy</name>
<age>31</age>
<hobbies>
<hobby>cosplay</hobby>
<hobby>D and D</hobby>
</hobbies>
</Friend>
</FriendList>
114
QUICK REVIEW
<?xml version="1.0"?>
<name>Billy</name>
<age>31</age>
<hobbies>
<hobby>cosplay</hobby>
<hobby>D and D</hobby>
</hobbies>
</Friend>
</FriendList>
115
QUICK REVIEW
<?xml version="1.0"?>
<Friend>
<name>Billy</name>
<age>31</age>
<hobbies>
<hobby>cosplay</hobby>
<hobby>D and D</hobby>
</hobbies>
</Friend>
</FriendList>
116
QUICK REVIEW
Pre-processor command
<?xml version="1.0"?>
<FriendList> Root
<Friend>
<hobbies>
<hobby>cosplay</hobby> Inner Level Grouping
<hobby>D and D</hobby>
</hobbies>
</FriendList>
XML ELEMENTS
117
<?xml version="1.0"?>
<FriendList>
<Friend> Every Start Tag - End Tag combination
<name>Billy</name> is known as an
<age>31</age> ELEMENT
<hobbies> in an XML Document
<hobby>Avengers</hobby>
<hobby>DandD</hobby>
</hobbies>
</Friend>
<Friend>
<name>Idris</name>
<age>27</age>
<hobbies>
<hobby>Dr. Who</hobby>
</hobbies>
</Friend>
<Friend>
<name>Jordan</name>
<age>19</age>
<hobbies>
<hobby>Star Wars</hobby>
<hobby>My Little Pony</hobby>
</hobbies>
</Friend>
</FriendList>
XML ELEMENTS
118
<?xml version="1.0"?>
<FriendList>
<Friend> Every Start Tag - End Tag combination
<name>Billy</name> is known as an
<age>31</age> ELEMENT
<hobbies> in an XML Document
<hobby>Avengers</hobby>
<hobby>DandD</hobby>
</hobbies>
</Friend>
<Friend>
<name>Idris</name>
<age>27</age>
<hobbies>
<hobby>Dr. Who</hobby>
</hobbies>
</Friend>
<Friend> Hint:
<name>Jordan</name> How many elements are in this XML Document ?
i.e. How many unique start tags can you count?
<age>19</age>
<hobbies>
<hobby>Star Wars</hobby>
<hobby>My Little Pony</hobby>
</hobbies>
</Friend>
</FriendList>
XML ELEMENTS
119
<?xml version="1.0"?>
<FriendList>
<Friend> Every Start Tag - End Tag combination
<name>Billy</name> is known as an
<age>31</age> ELEMENT
<hobbies> in an XML Document
<hobby>Avengers</hobby>
<hobby>DandD</hobby>
</hobbies>
</Friend>
<Friend>
<name>Idris</name>
<age>27</age>
<hobbies>
<hobby>Dr. Who</hobby>
</hobbies>
</Friend>
<Friend> Hint:
<name>Jordan</name> How many elements are in this XML Document ?
i.e. How many unique start tags can you count?
<age>19</age>
<hobbies>
6
<hobby>Star Wars</hobby>
<hobby>My Little Pony</hobby>
</hobbies>
</Friend>
</FriendList>
120
TAG ATTRIBUTES
<Friend>
Billy <name>Billy</name>
31 <age>31</age>
cosplay <hobbies>
Avengers <hobby>cosplay</hobby>
DandD <hobby>Avengers</hobby>
<hobby>DandD</hobby>
</hobbies>
</Friend>
121
TAG ATTRIBUTES
(information about the TAG and NOT about the DATA)
TAG ATTRIBUTES
(information about the TAG and NOT about the DATA)
TAG ATTRIBUTES
(information about the TAG and NOT about the DATA)
<Friend>
Billy <name>Billy</name>
31 <age>31</age>
cosplay <gender>Male</gender>
Avengers </hobbies>
DandD <hobby>cosplay</hobby>
<hobby>Avengers</hobby>
<hobby>DandD</hobby>
</hobbies>
</Friend>
124
TAG ATTRIBUTES
(information about the TAG and NOT about the DATA)
<Friend>
Billy <name>Billy</name>
31 <age>31</age>
cosplay <gender>Male</gender> {correct}
Avengers </hobbies>
DandD <hobby>cosplay</hobby>
<hobby>Avengers</hobby>
<hobby>DandD</hobby>
</hobbies>
</Friend>
125
ELEMENT COMPONENTS
<city id = “nyc”> New York City </city>
126
ELEMENT COMPONENTS
<city id = “nyc”> New York City </city>
| start tag |
127
ELEMENT COMPONENTS
<city id = “nyc”> New York City </city>
|tag |
|name|
| start tag |
128
ELEMENT COMPONENTS
<city id = “nyc”> New York City </city>
|tag | | tag attribute |
|name| (optional)
| start tag |
129
ELEMENT COMPONENTS
<city id = “nyc”> New York City </city>
|end tag|
130
ELEMENT COMPONENTS
<city id = “nyc”> New York City </city>
|terminator|
|end tag|
131
ELEMENT COMPONENTS
<city id = “nyc”> New York City </city>
| content |
|-data-|
132
ELEMENT COMPONENTS
<city id = “nyc”> <town>York</town> </city>
| content |
|-data-|
- OR -
|- other elements - |
133
ELEMENT COMPONENTS
<city id = “nyc”>
<town>York</town>
</city>
| content |
|-data-|
- OR -
|- other elements- |
ELEMENT COMPONENTS
Empty Elements
<city></city>
| NO content |
|- NO data-|
ELEMENT COMPONENTS
Empty Elements
<city></city> - NOTHING between the ‘start’ tag and the ‘end’ tag
| NO content |
|- NO data-|
ELEMENT COMPONENTS
More Rules
<city id = “nyc”> New York City </city>
XML tag names are case sensitive: <TAG> <Tag> and <tag> are all different
XML Name may NOT begin with a number: <1Tag> is NOT allowed
XML Names may NOT contain any other punctuation characters: <Tag%> NO
XML Names can NOT have whitespace: <Tag Name> is NOT allowed
XML Name may NOT begin with XML in any case: <XMLTag> <xmlTag> NO
137
ELEMENT COMPONENTS
More Rules
<city id = “nyc”> New York City </city>
XML tag names are case sensitive: <TAG> <Tag> and <tag> are all different
XML Name may NOT begin with a number: <1Tag> is NOT allowed
XML Names may NOT contain any other punctuation characters: <Tag%> NO
XML Names can NOT have whitespace: <Tag Name> is NOT allowed
XML Name may NOT begin with XML in any case: <XMLTag> <xmlTag> NO
138
ELEMENT COMPONENTS
More Rules
<city id = “nyc”> New York City </city>
XML tag names are case sensitive: <TAG> <Tag> and <tag> are all different
XML Name may NOT begin with a number: <1Tag> is NOT allowed
XML Names may NOT contain any other punctuation characters: <Tag%> NO
XML Names can NOT have whitespace: <Tag Name> is NOT allowed
XML Name may NOT begin with XML in any case: <XMLTag> <xmlTag> NO
139
ELEMENT COMPONENTS
More Rules
<city id = “nyc”> New York City </city>
XML tag names are case sensitive: <TAG> <Tag> and <tag> are all different
XML Name may NOT begin with a number: <1Tag> is NOT allowed
XML Names may NOT contain any other punctuation characters: <Tag%> NO
XML Names can NOT have whitespace: <Tag Name> is NOT allowed
XML Name may NOT begin with XML in any case: <XMLTag> <xmlTag> NO
140
ELEMENT COMPONENTS
More Rules
<city id = “nyc”> New York City </city>
XML tag names are case sensitive: <TAG> <Tag> and <tag> are all different
XML Name may NOT begin with a number: <1Tag> is NOT allowed
XML Names may NOT contain any other punctuation characters: <Tag%> NO
XML Names can NOT have whitespace: <Tag Name> is NOT allowed
XML Name may NOT begin with XML in any case: <XMLTag> <xmlTag> NO
141
ELEMENT COMPONENTS
More Rules
<city id = “nyc”> New York City </city>
XML tag names are case sensitive: <TAG> <Tag> and <tag> are all different
XML Name may NOT begin with a number: <1Tag> is NOT allowed
XML Names may NOT contain any other punctuation characters: <Tag%> NO
XML Names can NOT have whitespace: <Tag Name> is NOT allowed
XML Name may NOT begin with XML in any case: <XMLTag> <xmlTag> NO
142
ELEMENT COMPONENTS
More Rules
<city id = “nyc”> New York City </city>
XML tag names are case sensitive: <TAG> <Tag> and <tag> are all different
XML Name may NOT begin with a number: <1Tag> is NOT allowed
XML Names may NOT contain any other punctuation characters: <Tag%> NO
XML Names can NOT have whitespace: <Tag Name> is NOT allowed
XML Name may NOT begin with XML in any case: <XMLTag> <xmlTag> NO
143
ELEMENT COMPONENTS
More Rules
<city id = “nyc”> New York City </city>
ELEMENT COMPONENTS
More Rules
<city id = “nyc”> New York City </city>
ELEMENT COMPONENTS
More Rules
<city id = “nyc”> New York City </city>
ELEMENT COMPONENTS
More Rules
<compare>6 <7 & 7> 6 ‘natch’</compare>
ELEMENT COMPONENTS
More Rules
<compare>6
W R <7 O &N
7> 6G‘natch’</compare>
! ! ! ! !
Escaping Characters NOT allowed:
ELEMENT COMPONENTS
More Rules
<compare>6 <7 & 7> 6 ‘natch’</compare>
ELEMENT COMPONENTS
More Rules
<compare>6 <7 & 7> 6 ‘natch’</compare>
ELEMENT COMPONENTS
More Rules
<compare>6 <7 & 7> 6 ‘natch’</compare>
ELEMENT COMPONENTS
More Rules
<compare>6 <7 & 7> 6 ‘natch’</compare>
ELEMENT COMPONENTS
More Rules
<compare>6 <7 & 7> 6 ‘natch’</compare>
ELEMENT COMPONENTS
More Rules
<compare>6 <7 & 7> 6 ‘natch’</compare>
ELEMENT ATTRIBUTES
More Rules
<city id = “nyc”> New York City </city>
- can imbed:
ELEMENT ATTRIBUTES
More Rules
<city id = “nyc”> New York City </city>
- can imbed:
ELEMENT ATTRIBUTES
More Rules
<city id = “nyc”> New York City </city>
ELEMENT ATTRIBUTES
More Rules
<city id = “nyc”> New York City </city>
XML Attributes can NOT have the same name inside a tag:
158
ELEMENT ATTRIBUTES
More Rules
<city id = “nyc”> New York City </city>
XML Attributes can NOT have the same name inside a tag:
ELEMENT ATTRIBUTES
More Rules
<city id = “nyc”> New York City </city>
XML Attributes can NOT have the same name inside a tag:
ELEMENT ATTRIBUTES
More Rules
<city id = “nyc”> New York City </city>
XML Attributes can NOT have the same name inside a tag:
COMMENTS
<!-- This is an XML Comment -->
COMMENTS
<!-- This is an XML Comment -->
COMMENTS
<!-- This is an XML Comment -->
COMMENTS
<!-- This is an XML Comment -->
<Friend>
<name>Joe Bloggs</name>
<age>25</age>
</Friend>
Can be easily changed (expanded) to
<Friend>
<name>Joe Bloggs</name>
<age>25</age>
<job>Student</job>
<address>123 Fake St.</address>
<courses>
<course>CS1032</course>
<course>CS2034</course>
</courses>
</Friend>
166
<Friend>
<name>Joe Bloggs</name>
<age>25</age>
</Friend>
Can be easily changed (expanded) to
<Friend>
<name>Joe Bloggs</name>
<age>25</age>
<job>Student</job>
<address>123 Fake St.</address>
<courses>
<course>CS1032</course>
<course>CS2034</course>
</courses>
</Friend>
167
<Friend>
<name>Joe Bloggs</name>
<age>25</age>
</Friend>
Can be easily changed (expanded) to
<Friend>
<name>Joe Bloggs</name>
<age>25</age>
<job>Student</job>
<address>123 Fake St.</address>
<courses>
<course>CS1032</course>
<course>CS2034</course>
</courses>
</Friend>
168
<Friend>
<name>Joe Bloggs</name>
<age>25</age> In most cases the computer
</Friend> will ignore the extra tags (if it
Can be easily changed (expanded) to has not yet been programed
<Friend> to understand them).
<name>Joe Bloggs</name>
<age>25</age>
<job>Student</job> Backwards combability.
<address>123 Fake St.</address>
<courses>
<course>CS1032</course>
<course>CS2034</course>
</courses>
</Friend>
169
<Friend>
<name>Billy Bob Hillbilly</name>
<age>31</age>
</Friend>
<Friend>
<name>
<first>Billy</first>
<middle>Bob</middle>
<last>Hillbilly</last>
</name>
<age>31</age>
</Friend>
170
<Friend>
<name>Billy Bob Hillbilly</name>
<age>31</age>
</Friend>
<Friend>
<name>
<first>Billy</first>
<middle>Bob</middle>
<last>Hillbilly</last>
</name>
<age>31</age>
</Friend>
171
<Friend>
<name>
<first>Billy</first>
<middle>Bob</middle>
<last>Hillbilly</last>
</name>
<age>31</age>
</Friend>
172
XML NAMESPACE
Processing XM Documents:
- may have to combine two or more documents into a single work unit
- how to ensure Doc1 never uses the same tag as Doc2 ???
XML NAMESPACE
174
Conflict Example:
File1.xml: File2.xml:
<?xml version="1.0"?> <?xml version="1.0"?>
<Friends> <Worker>
<person> <person>
<name>Billy</name> <name>
<age>31</age> <first>Frazer</first>
<hobbies> <last>Fur</last>
<hobby>cosplay</hobby> </name>
<hobby>Avengers</hobby> <age>31</age>
<hobby>DandD</hobby> <schedule>
</hobbies> <day>Tuesday</day>
</person> <day>Thursday</day>
</schedule>
<person> </person>
<name>Idris</name> </Worker>
<age>27</age>
<hobbies>
<hobby>Dr. Who</hobby>
</hobbies>
</person>
</Friends>
XML NAMESPACE 175
Combined XML Documents in One File - fCombined.xml
<?xml version="1.0"?> <!– File1.xml →
<Friends>
<person>
<name>Billy</name>
<age>31</age>
<hobbies>
<hobby>cosplay</hobby>
<hobby>Avengers</hobby>
<hobby>DandD</hobby>
</hobbies>
</person>
<person>
<name>Idris</name>
<age>27</age>
<hobbies>
<hobby>Dr. Who</hobby>
</hobbies>
</person>
</Friends>
Conflict Example:
File1.xml: File2.xml:
<?xml version="1.0"?> <?xml version="1.0"?>
<Friends> <Worker>
<person> <person>
<name>Billy</name> <name>
<age>31</age> <first>Frazer</first>
<hobbies> <last>Fur</last>
<hobby>cosplay</hobby> </name>
<hobby>Avengers</hobby> <age>31</age>
<hobby>DandD</hobby> <schedule>
</hobbies> <day>Tuesday</day>
</person> <day>Thursday</day>
</schedule>
<person> </person>
<name>Idris</name> </Worker>
<age>27</age>
<hobbies>
<hobby>Dr. Who</hobby>
</hobbies>
</person>
</Friends>
XML NAMESPACE 177
Combined XML Documents in One File - fCombined.xml
<?xml version="1.0"?> <!– File1.xml →
<Friends>
<person>
<name>Billy</name>
<age>31</age>
<hobbies>
<hobby>cosplay</hobby>
<hobby>Avengers</hobby>
<hobby>DandD</hobby>
</hobbies>
</person>
<person>
<name>Idris</name>
<age>27</age>
<hobbies>
<hobby>Dr. Who</hobby>
</hobbies>
</person>
</Friends>
- fancy way of just saying ‘associate a last name with each document’
- give each a document a ‘last name’ and treat the tag as a ‘first name’
- fancy way of just saying ‘associate a last name with each document’
- give each a document a ‘last name’ and treat the tag as a ‘first name’
- BUT !!!!
- BUT !!!!
<Friends>
To:
<ns1:Friends xmlns:ns1=“http://cs1.ca/cs1032.html">
XML NAMESPACE
182
- BUT !!!!
<Friends> NamespaceURI
Namespace Uniform Resource Identifier
To: root ( usually a URL )
<ns1:Friends xmlns:ns1="http://cs1.ca/cs1032.html">
<person> <ns1:person>
<name>Idris</name> <ns1:name>Idris</ns1:name>
<age>27</age> <ns1:age>27</ns1:age>
<hobbies> <ns1:hobbies>
<hobby>Dr. Who</hobby> <ns1:hobby>Dr. Who</ns1:hobby>
</hobbies> </ns1:hobbies>
</person> </ns1:person>
</Friends> </ns1:Friends>
XML NAMESPACE
184
<person> <ns1:person>
<name>Idris</name> <ns1:name>Idris</ns1:name>
<age>27</age> <ns1:age>27</ns1:age>
<hobbies> <ns1:hobbies>
<hobby>Dr. Who</hobby> <ns1:hobby>Dr. Who</ns1:hobby>
</hobbies> </ns1:hobbies>
</person> </ns1:person>
</Friends> </ns1:Friends>
XML NAMESPACE
185
<?xml version="1.0"?>
<?xml version="1.0"?>
<ns2:Worker xmlns:ns2="http://cs1.ca/workers">
<Worker>
<ns2:person>
<person>
<ns2:name>
<name>
<ns2:first>Frazer</ns2:first>
<first>Frazer</first>
<ns2:last>Fur</ns2:last>
<last>Fur</last>
</ns2:name>
</name>
<ns2:age>31</ns2:age>
<age>31</age>
<ns2:schedule>
<schedule>
<ns2:day>Tuesday</ns2:day>
<day>Tuesday</day>
<ns2:day>Thursday</ns2:day>
<day>Thursday</day>
</ns2:schedule>
</schedule>
</ns2:person>
</person>
</n2:Worker>
</Worker>
XML NAMESPACE
186
<?xml version="1.0"?>
<?xml version="1.0"?>
<ns2:Worker xmlns:ns2="http://cs1.ca/workers">
<Worker>
<ns2:person>
<person>
<ns2:name>
<name>
<ns2:first>Frazer</ns2:first>
<first>Frazer</first>
<ns2:last>Fur</ns2:last>
<last>Fur</last>
</ns2:name>
</name>
<ns2:age>31</ns2:age>
<age>31</age>
<ns2:schedule>
<schedule>
<ns2:day>Tuesday</ns2:day>
<day>Tuesday</day>
<ns2:day>Thursday</ns2:day>
<day>Thursday</day>
</ns2:schedule>
</schedule>
</ns2:person>
</person>
</n2:Worker>
</Worker>
XML NAMESPACE
Combined XML Documents (Files) - fCombined.xml
187
<?xml version="1.0"?>
<ns1:Friends xmlns:ns1="http://cs1.ca/friends">
<ns1:person>
<ns1:name>Billy</ns1:name>
<ns1:age>31</ns1:age>
<ns1:hobbies>
<ns1:hobby>cosplay</ns1:hobby>
<ns1:hobby>Avengers</ns1:hobby>
<ns1:hobby>DandD</ns1:hobby>
</ns1:hobbies>
</ns1:person>
<ns1:person>
<ns1:name>Idris</ns1:name>
<ns1:age>27</ns1:age>
<ns1:hobbies>
<ns1:hobby>Dr. Who</ns1:hobby>
</ns1:hobbies>
</ns1:person>
</ns1:Friends>
<ns2:Worker xmlns:ns2="http://cs1.ca/workers">
<ns2:person>
<ns2:name>
<ns2:first>Frazer</ns2:first>
<ns2:last>Fur</ns2:last>
</ns2:name>
<ns2:age>31</ns2:age>
<ns2:schedule>
<ns2:day>Tuesday</ns2:day>
<ns2:day>Thursday</ns2:day>
</ns2:schedule>
</ns2:person>
</n2:Worker>
XML NAMESPACE
Combined XML Documents (Files) - fCombined.xml
188
<?xml version="1.0"?>
<ns1:Friends xmlns:ns1="http://cs1.ca/friends">
<ns1:person>
<ns1:name>Billy</ns1:name>
<ns1:age>31</ns1:age>
<ns1:hobbies>
<ns1:hobby>cosplay</ns1:hobby>
<ns1:hobby>Avengers</ns1:hobby>
<ns1:hobby>DandD</ns1:hobby>
</ns1:hobbies>
</ns1:person>
<ns1:person>
<ns1:name>Idris</ns1:name>
<ns1:age>27</ns1:age> Still have an issue.
<ns1:hobbies>
<ns1:hobby>Dr. Who</ns1:hobby>
</ns1:hobbies>
</ns1:person> XML rules say we can
</ns1:Friends>
only have one root
<ns2:Worker xmlns:ns2="http://cs1.ca/workers">
<ns2:person> element!
<ns2:name>
<ns2:first>Frazer</ns2:first>
<ns2:last>Fur</ns2:last>
</ns2:name>
<ns2:age>31</ns2:age>
<ns2:schedule>
<ns2:day>Tuesday</ns2:day>
<ns2:day>Thursday</ns2:day>
</ns2:schedule>
</ns2:person>
</n2:Worker>
XML NAMESPACE
189
- BUT !!!!
What happens of the other developer is also uses foobar or mashes the first row of their keyboard?
<ns1:Friends xmlns:ns1="http://cs1.ca/cs1032.html">
XML NAMESPACE
191
- BUT !!!!
What happens of the other developer is also uses foobar or mashes the first row of their keyboard?
<ns1:Friends xmlns:ns1="http://cs1.ca/cs1032.html">
XML NAMESPACE
192
- BUT !!!!
What happens of the other developer is also uses foobar or mashes the first row of their keyboard?
<ns1:Friends xmlns:ns1="http://cs1.ca/cs1032.html">
XML NAMESPACE
193
- BUT !!!!
What happens of the other developer is also uses foobar or mashes the first row of their keyboard?
<ns1:Friends xmlns:ns1="http://cs1.ca/cs1032.html">
XML NAMESPACE
194
- BUT !!!!
What happens of the other developer is also uses foobar or mashes the first row of their keyboard?
<ns1:Friends xmlns:ns1="http://cs1.ca/cs1032.html">
XML NAMESPACE
195
- BUT !!!!
What happens of the other developer is also uses foobar or mashes the first row of their keyboard?
Namespace:
ONLY ONLY ONLY ONLY ONLY ONLY USED …..
XML NAMESPACE
197
Namespace:
ONLY ONLY ONLY ONLY ONLY ONLY USED …..
- 1.) when combing two or more XML documents into a SINGLE
computer file.
XML NAMESPACE
198
Namespace:
ONLY ONLY ONLY ONLY ONLY ONLY USED …..
- 1.) when combing two or more XML documents into a SINGLE
computer file.
- then you MUST use a namespace to differentiate !
XML NAMESPACE
199
Namespace:
ONLY ONLY ONLY ONLY ONLY ONLY USED …..
- 1.) when combing two or more XML documents into a SINGLE
computer file.
- then you MUST use a namespace to differentiate !
- 2.) in an XML Schema
- you ALWAYS use namespace in a schema
(… explanation when we cover Schemas )
XML NAMESPACE
200
Namespace:
ONLY ONLY ONLY ONLY ONLY ONLY USED …..
- 1.) when combing two or more XML documents into a SINGLE
computer file.
- then you MUST use a namespace to differentiate !
- 2.) in an XML Schema
- you ALWAYS use namespace in a schema
(… explanation when we cover Schemas )
OTHERWISE – Namespace is optional
- and never really used except 1. and 2. above
201
XML DOCUMENTS
Scenario:
XML DOCUMENTS
Scenario: