Upload
hop-huynh
View
233
Download
0
Embed Size (px)
Citation preview
8/3/2019 02 - XML - Fundamentals
1/26
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
eXtensible Markup Language
Fundamentals
eXtensible Markup Language Phan Vo Minh Thang
8/3/2019 02 - XML - Fundamentals
2/26
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
8/3/2019 02 - XML - Fundamentals
3/26
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
8/3/2019 02 - XML - Fundamentals
4/26
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
8/3/2019 02 - XML - Fundamentals
5/26
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
XML Lectures Notes XML Fundamentals
8/3/2019 02 - XML - Fundamentals
6/26
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
XML Lectures Notes XML Fundamentals
8/3/2019 02 - XML - Fundamentals
7/26
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
XML Lectures Notes XML Fundamentals
8/3/2019 02 - XML - Fundamentals
8/26
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
XML Lectures Notes XML Fundamentals
8/3/2019 02 - XML - Fundamentals
9/26
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
8/3/2019 02 - XML - Fundamentals
10/26
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
< e s o 0 > < ate a > ectu es otes u da e ta s
Attributes
Attach additional information to elements An attribute is a name-value pair attached to an elements
start-tag
One element can have more than one attribute
Name and value are separated by = and optional whitespace
Attribute value is enclosed in double or single quotation marks
03-5712121
Attribute order is not significant
Example 2-4
Alan Turing
8/3/2019 02 - XML - Fundamentals
11/26
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
Attributes and Elements
When and whether one should use child elements orattributes to hold information?
Attributes are for metadata about the element, while elements arefor the information itself
Each element may have no more than one attribute with agiven name
The value of attribute is simply a text string limited instructure
An element-based structure is a lot more flexible and
extensible If you are designing your own XML vocabulary, it is up to
you to decide when to use which
8/3/2019 02 - XML - Fundamentals
12/26
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
XML Names
Rules for naming elements, attributes May contain essentially any alphanumeric character
and non-english letters, numbers, and ideograms
May contain underscore(_), period (.), and hyphen (-)
XML may not contain whitespace of any kind
All names beginning with the string xml (in anycombination of case) are reserved for standardization inW3C XML-related specifications
Start with either letters. ideograms and underscore (_)
No limit to the name length
8/3/2019 02 - XML - Fundamentals
13/26
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
XML Names (Cont.)
HTML elements in XML are always in uppercase XML elements are frequently written in lowercase
When a name consists of several words, the words are usually
separated by a hyphen (-)
address-book
OR
The first letter of each word in XML elements are frequently inuppercase and no separation character
AddressBook
8/3/2019 02 - XML - Fundamentals
14/26
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
Element names example
Which tags are named correctly?
8/3/2019 02 - XML - Fundamentals
15/26
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
Entity References
What if the character data inside an element contains < ? Entity reference when an application parses an XML
document, it replaces the entity reference with the actual
characters to which the entity reference refers Entity references are markups
XML predefines 5 entity references you can define more
the greater-than sign
" the straight, double quotation marks (")
' the straight single quote (')
8/3/2019 02 - XML - Fundamentals
16/26
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
CDATA Sections
What if your character data have a lot of
8/3/2019 02 - XML - Fundamentals
17/26
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
Comments
XML documents can be commented so that coauthors canleave notes for each other and themselves
Begin with
The double hyphen -- should not appear anywhere inside thecomment until the closing -->
Comments may appear anywhere in the character data ofa document
Comments may appear before or after the root element
Comments may not appear inside a tag or inside another
comment Comments are strictly for making the raw source code of
an XML document more legible to human readers
8/3/2019 02 - XML - Fundamentals
18/26
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
The XML Declaration
XML documents should (but not have to) begin with anXML declaration
The XML declaration must be the first thing in the document
It must not be preceded by any comments, whitespace
An XML declaration specifies encoding and standalone
Encoding: specify the character set used in the XML document
Default to Unicode/UTF8
Standalone: if the value is "no", then an application may berequired to read an external DTD to determine the proper valuesfor parts of the document
8/3/2019 02 - XML - Fundamentals
19/26
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
Rules for Well-Formed XML
Rule 1: Mandatory closing tags The set of tags is unlimited but all container tags must have end
tags
Example of legal XML Phan Minh Vo Thang
Associate Professor 25
Rule 2: There must be exactly one root element
8/3/2019 02 - XML - Fundamentals
20/26
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
Rules for Well-Formed XML (Cont.)
Rule 3: Proper element nesting All tags must be nested correctly. Like HTML, XML can intermix
tags and text, but tags may not overlap each other.
Legal XML Hao-Ren Ke is an
pioneerforComputerized Interlibrary Loanin Taiwan
Illegal XML
ClavenXML provides a data bus
8/3/2019 02 - XML - Fundamentals
21/26
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
Rules for Well-Formed XML (Cont.)
Rule 4: Attribute values must be single or double quoted Legal
Illegal
Rule 5: An element may not have two attributes with thesame name
Rule 6: Comments and processing instructions may not
appear inside tags Rule 7: No unescaped < or & signs may occur in the
character data of an element or attributes
8/3/2019 02 - XML - Fundamentals
22/26
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
Rules for Well-Formed XML
Rule 8: Empty elements must be written in an abbreviatedform using special XML syntax.
Legal
is equivalent to
Illegal
8/3/2019 02 - XML - Fundamentals
23/26
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
Four Common Errors
Forget End Tags Forget that XML is Case Sensitive
Introduce Spaces in the Name of Element
Forget the Quotes for Attribute Value
8/3/2019 02 - XML - Fundamentals
24/26
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
Exercise
Is it a well-formed XML document?
The XML Handbook
Prentice Hall PTR
Charles F. Goldfarb
XML Basics
Carolyn Strong
April 17
8/3/2019 02 - XML - Fundamentals
25/26
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
Well-formed checking using tools
8/3/2019 02 - XML - Fundamentals
26/26
eXtensible Markup LanguageLectu rer : Phan Vo Minh Than g MSc.
Info
Course name:
Special Selected Topic in
Information System Section: XML Fundamentals
Number of slides: 26
Updated date: 12/02/2006 Contact: Mr.Phan Vo Minh Thang