Validation and Namespaces

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+)>

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

<!ATTLIST chess:game xmlns:chess
    CDATA "" #FIXED>
<!ATTLIST game xmlns CDATA
    "" #FIXED>

This is rather annoying and inconvenient. Fortunately, the parameterization techniques discussed in Item 7 enable you to adjust the namespace prefix within any given document by overriding a couple of parameter entity references in the internal DTD subset.

All other schema languages are namespace aware and do validate against the namespace URI and local name rather than the prefixed name.

Aside from this small if annoying inconsistency with DTDs, namespaces are not particularly burdensome. The classes of elements defined by different namespace URIs often significantly simplify XML processing. It's like the difference between writing a system that knows only first names and one that knows both first and family names. When there are a million different people named John in the world, it really helps to know who is John Jones and who is John Finkelstein. While there are well-designed legacy XML applications such as DocBook that predate namespaces and thus don't use them, all new XML applications should use namespaces.

     Python   SQL   Java   php   Perl 
     game development   web development   internet   *nix   graphics   hardware 
     telecommunications   C++ 
     Flash   Active Directory   Windows