XML: Parts 1–2
Version 1.1
- Hour 1: Hype
- Hour 2: Introduction to writing XML
Hype
Discussion:
- The textbook author assumes (though not strongly) that readers are familiar with HTML. Is this a true assumption?
- XML is now widely used for storing and interchanging structured data. It no longer needs hype.
- Name and describe some applications of XML.
- To what extent are these related or not related to the Web and the Internet in general?
- What is the W3C?
- Origins: SGML → HTML; SGML → XML
- What is a markup language?
- Relation between XML and HTML (XHTML, HTML 5)
- XML is a metalanguage. What does this mean?
Introduction to Writing XML
XML Building Blocks
Make sure we understand:
- Tags
- A space before the / is not required in XML, but some people use it for compatibility with obsolete web browsers.
- Elements
- Attributes
- Content
- Text
Five Commandments
Discussion: students give examples that violate each commandment:
- Case-sensitive tags
- Opening tags must have closing tags except for abbreviated empty elements.
- Elements may not overlap.
- Attribute values must be quoted.
- You can use either single or double quotes.
- There must be one (and only one) root element in a document.
A document is well-formed if it obeys these five rules.
Tree Structure
These rules imply that an XML document is tree structured.
- Sketch the tree representation of the pets document at top of p. 26.
- What is a tree?
- Remember B-tree indexes? B-trees are just one kind of tree.
- A tree consists of a root node and a set of subtrees; each subtree is a tree, and the subtrees are disjoint (non-overlapping).
Remember that the relational model came into favor after earlier "hierarchical" (tree) and "network" (graph) data models. Now the hierarchical model is back, in the form of XML!
Special Symbols
Certain symbols have special meaning in XML and cannot be written verbatim—actually this is a bit of an overstatement; some of them can be written verbatim, but not in all contexts.
- & must be &
- < must be <
- > sometimes must be >
- ' sometimes must be '
- " sometimes must be "
XML Declaration
- What's it for?
- What does it look like?
- Is it an element?
XML Editors
I recommend using a good text editor. Emacs handles XML well; so do many others. Not Notepad; Windows users should consider Notepad++.
First XML Document
Discussion:
- Explain the Tall Tales sample document, Listing 2.2
- What is the CSS style sheet for, Listing 2.3? Don't mind the details.
- How is the document linked (or "attached") to the style sheet?
- What does the document look like in a web browser, without the style sheet, and with the style sheet?
Exercises
On page 40, #1–2.
In addition, check if the document is well-formed:
$ xmlwf FILE
or
$ xmllint --noout FILE