http://www.dcs.bbk.ac.uk/~ptw/
<
and >
charactershead
element:
<head> <title>Elements and tags</title> </head>
<head>
is
the start tag of the element</head>
is
the end tag of the elementhead
is the
element name<title>Elements and tags</title>
is the element contentshtml
element, with a head
element followed by a body
element
<html> <head> <title>Document title</title> </head> <body> <h1>First level heading</h1> <p> First paragraph </p> <p> Second paragraph </p> ... </body> </html>
<
and >
inclusive
(i.e., in red
on slides) is markup;>
and <
exclusive
(i.e., in blue
on slides) is character dataElement name | Description |
---|---|
h1 ...h6 |
headings |
p |
paragraph |
table |
table |
tr |
table row |
ol |
ordered list |
ul |
unordered list |
li |
list item |
form |
form to fill in (see later) |
hr |
horizontal rule |
pre |
preformatted text |
div |
division (often used for formatting with stylesheets) |
Element name | Description |
---|---|
code |
sample code |
em |
emphasis |
a |
anchor (for hyperlinks) |
img |
inline image |
td |
table data item |
span |
often used for formatting with stylesheets |
The HTML source code for the previous slide looks as follows:
<h1>Some In-line HTML Elements</h1> <table> <tr> <th>Element name</th> <th>Description</th> </tr> <tr> <td><code>code</code></td> <td>sample code</td> </tr> ... <tr> <td><code>span</code></td> <td>often used for formatting with stylesheets</td> </tr> </table> <ul> <li>in-line elements are displayed in the current line</li> ... </ul>
<tagname attribute="value">
<a href="http://example.org/index.html">
<img src="example.jpg"
alt="An example image">
<img src="example.jpg"
alt="An example image">
<img alt="An example image"
src="example.jpg">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">the above syntax will be explained later
<!DOCTYPE html>
head
, body
head
, body
, p
, li
hr
, br
, img
Representing information about a collection of classical CDs:
cd-collection.xml
<CDcollection> <CD> <soloist>Martha Argerich</soloist> <orchestra>London Symphony Orchestra</orchestra> <conductor>Claudio Abbado</conductor> <date>1968</date> <performance> <composer>Frederic Chopin</composer> <composition>Piano Concerto No. 1</composition> </performance> <performance> <composer>Franz Liszt</composer> <composition>Piano Concerto No. 1</composition> </performance> </CD> <CD> <composer>Antonin Dvorak</composer> <performance> <composition>Symphony No. 9</composition> <orchestra>Vienna Philharmonic</orchestra> <conductor>Kirill Kondrashin</conductor> <date>1980</date> </performance> <performance> <composition>American Suite</composition> <orchestra>Royal Philharmonic</orchestra> <conductor>Antal Dorati</conductor> <date>1984</date> </performance> </CD> </CDcollection>
Meaning of acronyms:
svg-example.xml
<svg> <g style="fill-opacity:0.7; stroke:black; stroke-width:0.1cm;"> <circle cx="6cm" cy="2cm" r="100" style="fill:red;" transform="translate(0,50)" /> <circle cx="6cm" cy="2cm" r="100" style="fill:blue;" transform="translate(70,150)" /> <circle cx="6cm" cy="2cm" r="100" style="fill:green;" transform="translate(-70,150)"/> </g> </svg>
<math> <mroot> <mrow> <mn>1</mn> <mo>-</mo> <mfrac> <mi>x</mi> <mn>2</mn> </mfrac> </mrow> <mn>3</mn> </mroot> </math>and looks like this when viewed with a MathML-capable browser, and this when using MathJax
rss-fragment.xml
<rss> <channel> <title> ... </title> ... <item> <title> ... </title> <description> ... </description> <link> ... </link> <pubDate> ... </pubDate> </item> ... <item> <title> ... </title> <description> ... </description> <link> ... </link> <pubDate> ... </pubDate> </item> <channel> </rss>
html
A
precedes start tag of B
,
end tag of B
must precede end tag of A
<A>
is different to <a>
Attribute values can be enclosed in either single quotes or
double quotes. This allows one to use quotes inside attribute
values, such as height='72"'
.
<?xml version="1.0"?>
<?
and end with
?>
are called processing instructions,
e.g. to specify a stylesheet<hr/>
for
<hr></hr>
<!--
and
-->
<!--changed 10/1/01-->
<![CDATA[
and ends with ]]>
<![CDATA[<!--changed 10/1/01-->]]>
The XML declaration can also specify the character encoding used,
using the encoding
attribute, and whether or not the
document is dependent on others, using the standalone
attribute. Putting this information inside the document makes it
self-identifying, which is preferable to using file
extensions, for example.
Processing instructions contain instructions which are supposed to be passed on to applications processing the document.
&
and #
characters;
end with ;
character≤
for ≤ (less than or equal to)א
for א (Hebrew aleph character)&
(&
),
<
(<
),
>
(>
),
"
("
),
'
('
)<
, e.g., can be obtained using
<
,
<
or
<
Single quotes and double quotes have special meaning in XML in
that they are used to delimit attribute values. If, for example,
we want to use a double quote to represent inches inside an attribute
value delimited using double quotes, we can use the quot
entity to do so as follows: height="72""
.
Now the value of the height
attribute returned by an
XML parser will be 72"
.
set
element<html xmlns="http://www.w3.org/1999/xhtml" ... > ... <svg xmlns="http://www.w3.org/2000/svg" ... > ... </svg> ... <math xmlns="http://www.w3.org/1998/Math/MathML"> ... </math> ... </html>
namespace:local-name
<http://www.w3.org/2000/svg:circle ... />
http://www.w3.org/2000/svg
is a URI and namespace<... xmlns:svg="http://www.w3.org/2000/svg"> <p>A circle looks like this ... <svg:circle ... /> ... </...>
xmlns:svg
attribute
http://www.w3.org/2000/svg
svg
xmlns="URI"
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:svg="http://www.w3.org/2000/svg"> ... <p>A circle looks like this <svg:svg ... > ... <svg:circle ... /> ... </svg:svg> and has ... </p> </html>
html
and
p
are in the default namespace (http://www.w3.org/1999/xhtml
)svg
and circle
are in the
http://www.w3.org/2000/svg
namespacesvg
is used both as a prefix and as an element namesvg
in front of the element name svg
?<html xmlns="http://www.w3.org/1999/xhtml" ... > ... <svg xmlns="http://www.w3.org/2000/svg" ... > ... </svg> ... <math xmlns="http://www.w3.org/1998/Math/MathML"> ... </math> ... </html>
html
element and its
descendants is http://www.w3.org/1999/xhtml
svg
element
and its descendants is http://www.w3.org/2000/svg
math
element and its descendants is
http://www.w3.org/1998/Math/MathML
pi
built in to MathML23.45
"abc"
true
null
XML CDCollection
example from earlier,
represented in JSON
{ "CDs": [ { "soloist": "Martha Argerich", "orchestra": "London Symphony Orchestra", "conductor": "Claudio Abbado", "date": 1968, "performances": [ { "composer": "Frederic Chopin", "composition": "Piano Concerto No. 1" }, { "composer": "Franz Liszt", "composition": "Piano Concerto No. 1" } ] }, { "composer": "Antonin Dvorak", "performances": [ { "composition": "Symphony No. 9", "orchestra": "Vienna Philharmonic", "conductor": "Kirill Kondrashin", "date": 1980 }, { "composition": "American Suite", "orchestra": "Royal Philharmonic", "conductor": "Antal Dorati", "date": 1984 } ] } ] }
programme
. A
programme
has a degree
, whose value in
this case is "MSc", and a year
, whose value
in this case is "2018/19". These elements are followed by the
results
for the programme. The results
are partitioned into distinction
, merit
,
pass
and fail
. Within each is a sequence of
name
elements, each containing the name of a person
having achieved the corresponding result
for the
programme
. The actual results are as follows:
Jemima Puddle-Duck and Peter Rabbit obtained distinctions,
Tom Kitten obtained a merit, and Samuel Whiskers failed
(nobody obtained only a pass).teaches
with attributes course
and
lecturer
, representing the relationship
between courses taught on an MSc programme and the lecturers who
teach them. Give an XML document which represents a relation
instance containing two tuples.
(You are free to make up your own course and lecturer names.)HTML is covered in Chapter 1 and XML in Chapter 2 of [Moller and Schwartzbach]. XML is covered in Chapter 1 of [Jacobs]. HTML and XML are mentioned in passing in Chapter 4 of [Comer].