Validation and Namespaces

DTDs, unfortunately, are not namespace aware. When writing a DTD for a document that uses namespaces, you must declare the prefixed names, as shown below.

<!ELEMENT chess:game (chess:move+)>
<!ELEMENT chess:move (#PCDATA)>

If the documents don't use a prefix, you declare the unprefixed names instead.

<!ELEMENT game (move+)>
<!ELEMENT move (#PCDATA)>

You must further declare the namespace attributes just as you would any other attribute.

<!ATTLIST chess:game xmlns:chess
    CDATA "http://namespaces.cafeconleche.org/chess" #FIXED>
<!ATTLIST game xmlns CDATA
    "http://namespaces.cafeconleche.org/chess" #FIXED>

This is rather annoying and inconvenient. Fortunately, the parameterization techniques discussed in Item 7 enable ...

Get Effective XML: 50 Specific Ways to Improve Your XML now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.