[EMAIL PROTECTED] wrote:
> > Are you aware of the inherent peril of trying to validate
> > documents with namespaces using a DTD grammar?
> 
> ? That DTD's don't support ns? Yes.

Good. :)

> >  There are
> > tricks to be used, but it doesn't have anything to do with
> > the parser -- just the grammar and the instance document --
> > and it's not pretty.
> 
> I would appreciate being enlightened.

DTDs don't support namespaces, as you know, so your DTD
grammar must be defined using the same prefixes that are 
used in your document. For example:

  <!ELEMENT a:foo (b:bar)*>
  <!ATTLIST a:foo xmlns:a CDATA #FIXED 'NSa'>
  <!ELEMENT b:bar (EMPTY)>
  <!ATTLIST b:bar xmlns:b CDATA #FIXED 'NSb'>

and the document must use the same prefixes:

  <!DOCTYPE a:foo SYSTEM 'grammar.dtd'>
  <a:foo xmlns:a='NSa'>
   <b:bar xmlns:b='NSb'>
  </a:foo>

However, this is a little impractical to mandate what
prefixes are actually used in the document. So there's a
common parameter entity trick that can be used to change
the prefixes in the DTD itself. Here's an example:

  <!ENTITY % p 'a:'>
  <!ENTITY % q ':a'>
  <!ENTITY % foo '%p;foo'>
  <!ENTITY % xmlns 'xmlns%q;'>

  <!ELEMENT %foo; (EMPTY)>
  <!ATTLIST %foo; %xmlns; CDATA #FIXED 'NSa'>

You need to do the following: 1) use parameter entities 
to define the namespace prefix to use for element names
and the namespace suffix to use as part of the "xmlns"
attibute (note that the entities contain the colons);
and 2) use those parameter entities to declare more
parameter entities that define the element names and
xmlns attribute names for those elements. You have to
do the second part because when parameter entities
are referenced outside of literal values, a space is
inserted before and after the replacement text. [This
is defined in the spec.]

Once done, each document instance can override the
namespace prefixes by using the internal subset, like
so:

  <!DOCTYPE x:foo SYSTEM 'grammar.dtd' [
  <!ENTITY % p 'x:'>
  <!ENTITY % q ':x'>
  ]>
  <x:foo xmlns:x='NSa'/>

People usually define the defaults in their DTD to be
the default namespace by setting %p and %q to be the
empty string. Then instance documents define what
prefixes will actually be used.

Obviously, this still has limitations but at least it's 
something...

-- 
Andy Clark * IBM, TRL - Japan * [EMAIL PROTECTED]

Reply via email to