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



Effective XML. 50 Specific Ways to Improve Your XML
Effective XML: 50 Specific Ways to Improve Your XML
ISBN: 0321150406
EAN: 2147483647
Year: 2002
Pages: 144

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net