O'Reilly logo

Effective XML: 50 Specific Ways to Improve Your XML by Elliotte Rusty Harold

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required