[Previous] [Contents] [Next]

Namespaces and Schemas


In Chapter 6, we looked at using namespaces for DTDs. Namespaces can be read and interpreted in well-formed XML documents. Unfortunately, DTDs are not well-formed XML. If you use a namespace in a DTD, the namespace cannot be resolved. Let's look at the following DTD as an example:


  <!DOCTYPE doc [
  <!ELEMENT doc (body)>
  <!ELEMENT body EMPTY>
  <!ATTLIST body bodyText CDATA #REQUIRED>
  <!ELEMENT HTML:body EMPTY>
  <!ATTLIST HTML:body HTML:bodyText CDATA #REQUIRED>
  ]>

A valid usage of this DTD is shown here:


  <doc><body bodyText="Hello, world"/></doc>

The following usage would be invalid, however, because the HTML:body element is not defined as a child element of the doc element:


  <doc><HTML:body bodyText="Hello, world"/></doc>

As far as the DTD is concerned, the HTML:body element and the body element are two completely different elements. A DTD cannot resolve a namespace and break it into its prefix (HTML) and the name (body). So the prefix and the name simply become one word. We want to be able to use namespaces but to be able to separate the prefix from the name. Schemas enable us to do this.

[Previous] [Contents] [Next]