<bk:book>

<bk:title>XML Sample</bk:title> <bk:pages>210</bk:pages> <bk:isbn>1-868640-34-2</bk:isbn> <authr:author>

<authr:firstname>John</authr:firstname> <authr:lastname>Smith</authr:lastname> <authr:title>Mr</authr:title>

</authr:author> </bk:book>

</library-entry>

In the example above, the <TITLE> tag is used twice, but in a different context, once within the <AUTHOR> element and once within the <BOOK> element. Note the use of the xmlns keyword in the namespace declaration. The XML recommendation does not specify whether a namespace declaration should point to a valid URI (Uniform Resource Identifier), only that it should be unique and persistent. There is not guarantee that the URI will point to a valid URI.

In the example, in order to illustrate the relationship of each element to a given namespace, we chose to specify the relevant namespace prefix before each element. However, it is assumed that once a prefix is applied to an element name, it applies to all descendants of that element unless it is over-ridden by another prefix. The extent to which a namespace prefix applies to elements in a document is defined as the namespace scope. If we were to use scoping, the above example would then look like this.

Example 2-2 A namespace example using namespace prefix

<?xml version”1.0”?>

<library-entry xmlns:authr=”authors.dtd” xmlns:bk=”books.dtd”> <bk:book>

<title>XML & WebSphere</title> <pages>210</pages> <isbn>1-868640-34-2</isbn> <authr:author>

<firstname>Joe</firstname>

<lastname>Bloggs</lastname>

<title>Mr</title> </authr:author>

</bk:book> </library-entry>

In this example, it is clear that all elements within the <BOOK> element are associated with the bk namespace, except for the elements within the <AUTHOR> element which belong to the authr namespace.

24 The XML Files: Development of XML/XSL Applications Using WebSphere Studio

Page 40
Image 40
IBM Version 5 manual Example 2-2 a namespace example using namespace prefix