Professional Documents
Culture Documents
1
8/20/2014
What is XML?
• XML stands for Extensible Markup Language
• XML is a meta-markup language.
– It is a language that lets you make up the tags you
need as you go along.
– HTML is also a markup language
• It is used to carry or store data
• XML is portable – can be used to represent a
photograph or a text file or both from the same
XML
• XML does not do anything
2
8/20/2014
XML vs HTML
• HTML describes presentation - HTML was
designed to display data and to focus on how
data looks.
• XML describes content – XML was designed to
describe data and to focus on what data is.
• XML files do not contain any formatting
information
3
8/20/2014
XML Parsers
• Parsers check an XML document’s syntax and
enable software programs to process the
mark-up data
• They can support the DOM or SAX (Simple API
for XML)
• All modern browsers have a built-in XML
parser.
4
8/20/2014
10
5
8/20/2014
11
12
6
8/20/2014
13
14
7
8/20/2014
XML declaration
<?xml version="1.0" encoding="ISO-8859-1"?>
<feedback>
<studentemail>s1@uom.ac.mu</studentemail>
<modulename code="CSE2041">Web Tech
II</modulename>
<moduleyear>2010</moduleyear>
<classsize>Adequate</classsize>
</feedback>
15
8
8/20/2014
18
9
8/20/2014
19
feedback.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<feedback>
<module>
<studentemail>s1@uom.ac.mu</studentemail>
<modulename code="CSE2041">Web Tech II</modulename>
<moduleyear>2010</moduleyear>
<classsize>Adequate</classsize>
</module>
<module>
<studentemail>s3@uom.ac.mu</studentemail>
<modulename code="CSE1041">Web Tech I</modulename>
<moduleyear>2010</moduleyear>
<classsize>Adequate</classsize>
</module></feedback> 20
10
8/20/2014
21
Element
<module>
22
11
8/20/2014
XML Syntax
23
12
8/20/2014
25
Answer
• To be discussed in class.
26
13
8/20/2014
27
Answer
• To be discussed in class.
28
14
8/20/2014
Attributes
• Attributes are simple name/value pairs associated with an
element.
• They are attached to the start-tag, but not to the end-tag.
• Names are separated from values by an equals sign and
optional whitespace.
• Values are enclosed in single or double quotation marks.
• Attributes must have values—even if that value is just an
empty string (“”)!
• Order in which attributes are included on an element is
irrelevant.
• E.g. Element person having attribute born as 1912-06-23
<person born="1912-06-23">Alan Turing</person>
29
30
15
8/20/2014
Answer
• To be discussed in class.
31
XML validation
• An XML is well-formed if the syntax is correct
(as described above)
• An XML is valid if it has been validated against
a schema or a DTD
32
16
8/20/2014
33
Comments in XML
• Comments start with the string <!— and end with
the string -->
• E.g
• <name nickname=’Shiny John’>
• <first>John</first>
• <!--John lost his middle name in a fire-->
• <middle></middle>
• <last>Doe</last>
• </name>
34
17
8/20/2014
35
Empty Elements
• Sometimes an element has no PCDATA.
<middle> element contained no name in the example that follows:
<name nickname=’Shiny John’>
<first>John</first>
<!--John lost his middle name in a fire-->
<middle></middle>
<last>Doe</last>
</name>
• In this case, the element can also be written using the
special empty element syntax (this syntax is also called a
self-closing tag):
• Here the start-tag does not need a separate end-tag. In all
other cases, both open and close tags are required.
36
18
8/20/2014
Empty Elements(2)
• Recall from earlier that the only place there can
be a space within the tag is before the closing >.
• This rule is slightly different when it comes to
empty elements.
• The / and > characters always have to be
together, so an empty element can be created
like this:
• <middle /> or <middle/> - Both valid.
• but NOT like this
• <middle/ > or <middle / > - Both invalid.
37
38
19
8/20/2014
Answer
• To be discussed in class.
39
40
20
8/20/2014
Answer
• To be discussed in class.
41
Next Week
• Lecture will be on XSD and valid XML
documents
42
21
8/20/2014
References
• CSE2003Y and CSE2041 Lecture Notes
• W3schools website
• XML Unleashed book
43
Questions
44
22