2008-10-01
Tyng-Ruey Chuang
trc@iis.sinica.edu.tw
Institute of Information Science
Academia Sinica, Taipei, Taiwan
We shall continue to study Extensible Markup Language (XML) 1.0 (Fourth Edition)
which is a W3C Recommendation published on August 16, 2006.
Link:
http://www.w3.org/TR/2006/REC-xml-20060816
We shall study Namespaces in XML 1.0 (Second Edition)
which is a W3C Recommendation published on August 16, 2006.
Link:
http://www.w3.org/TR/REC-xml-names/
Subjects to be covered this week:
Case studies:
In an XML Document Type Definition (DTD), one may use the following document type declarations to specify the structure of the XML documents that conform to the DTD:
element type declarations
attribute-list declarations
entity declarations which include
notation declarations
An example:
<!ENTITY % customer "name, street, city, state, zipcode"> <!ELEMENT invoice (%customer;, item, price, date)>
The above has the same effect as the following element declaration.
<!ELEMENT invoice (name, street, city, state, zipcode, item, price, date)>
In the following example, title
and number
are from different vocabularies:
<?xml version="1.0"?> <!-- both namespace prefixes are available throughout --> <bk:book xmlns:bk='urn:loc.gov:books' xmlns:isbn='urn:ISBN:0-395-36341-6'> <bk:title xml:lang="en">Cheaper by the Dozen</bk:title> <isbn:number>1568491379</isbn:number> </bk:book>
xmlns
.
It binds a namespace prefix (bk
) to a namespace name (urn:loc.gov:books
).
bk:book
is called a qualified name.
It has a prefix bk
and a local name book
.
The attribute name xml:lang
is a qualified name too;
it has a prefix xml
and a local name lang
.
xml
and xmlns
are reserved, and need not be declared.
The declaration xmlns='urn:loc.gov:books'
introduces
a default namespace for element book
and its children.
<?xml version="1.0"?> <!-- initially, the default namespace is "books" --> <book xmlns='urn:loc.gov:books' xmlns:isbn='urn:ISBN:0-395-36341-6'> <title>Cheaper by the Dozen</title> <isbn:number>1568491379</isbn:number> <notes> <!-- make HTML the default namespace for some commentary --> <p xmlns='http://www.w3.org/1999/xhtml'> This is a <i>funny</i> book! </p> </notes> </book>