|
A default namespace may be defined by omitting the prefix from an xmlns
attribute.
For example:
<?xml version="1.0" encoding="utf-8"?>
<book-review xmlns="http://www.book-review.com/">
<author>Harsh K. Critic</author>
<date>5 Nov 2006</date>
<book>A Brief History of the Twenty-First Century</book>
<comments>
This book should be read by every American.
Blah, blah, blah...
</comments>
<book-review>
And for the namespace for XHTML:
<html xmlns="http://www.w3.org/1999/xhtml">
Now we
can combine a default namespace with a books namespace using an explicit prefix
(books), to produce the following
example:
<?xml version="1.0" encoding="utf-8"?>
<book-reviews xmlns="http://reviews.info/"
xmlns:books="http://books.info/">
<author>Harsh K. Critic</author>
<date>5 Nov 2006</date>
<books:book>
<title>The World is Flat</title>
<subtitle>A Brief History of the Twenty-First Century</subtitle>
<author>Thomas Friedman</author>
<publisher>Farrar, Straus and Giroux</publisher>
<date-published>April 30, 2006</date-published>
<isbn>0374292795</isbn>
<pages>593</pages>
<price>30.00</price>
</books:book>
<comments>
This book should be read by every American.
Blah, blah, blah...
</comments>
</book-reviews>
Where we are also using the scoping of the books
attribute to implicitly associate the child elements of the books:book
element with the books namespace.
To see how your browser renders this XML, click here.
We could also have used a default namespace declaration in the book
element, as follows:
<?xml version="1.0" encoding="utf-8"?>
<book-reviews xmlns="http://reviews.info/">
<author>Harsh K. Critic</author>
<date>5 Nov 2006</date>
<book xmlns="http://books.info/">
<title>The World is Flat</title>
<subtitle>A Brief History of the Twenty-First Century</subtitle>
<author>Thomas Friedman</author>
<publisher>Farrar, Straus and Giroux</publisher>
<date-published>April 30, 2006</date-published>
<isbn>0374292795</isbn>
<pages>593</pages>
<price>30.00</price>
</book>
<comments>
This book should be read by every American.
Blah, blah, blah...
</comments>
</book-reviews>
To see how your browser renders this XML, click here.
|