W3C home > Mailing lists > Public > xmlschema-dev@w3.org > February 2002

Re: How to represent fixed namespace attributes?

From: Jeni Tennison <jeni@jenitennison.com>
Date: Mon, 25 Feb 2002 12:36:50 +0000
Message-ID: <53159240085.20020225123650@jenitennison.com>
To: "Pete Beazley" <pete@clearlyonline.com>
CC: xmlschema-dev@w3.org
Hi Pete,

> We much prefer being in a namespace-aware environment, but currently
> we need to be in both worlds (DTD and XML Schema) for a given XML
> instance and that causes some headaches at first. Our current
> resolution is to declare a set of potential namespace qualifiers as
> attributes in the DTD (without fixed values) so that their existence
> in the XML instance doesn't cause DTD validation errors. That way
> the same XML instance can be validated against a DTD and against an
> XML Schema. But, this approach still seems to be a bit of a hack
> since we are locking in a set of "allowed" prefixes into the DTD.
> Is there a better way for an XML instance to play nicely in both DTD
> and XML Schema worlds?

Anything mixing DTDs and namespaces is a real pain. I think that your
idea of declaring multiple namespace declaration attributes with
different prefixes is quite nice, since it will give a reasonable
amount of flexibility for the people writing the documents, without
giving them a lot of work to do. You do have to be a little careful
about the default namespace declarations overriding each other (for
example, you couldn't have both RDF and Dublin Core namespaces being
the default namespace at any one time) but you should be able to
handle that.

A 'standard' solution is used for XHTML and some other markup
languages. In the DTD, you declare a bunch of parameter entities that
record what prefix you're using:

<!ENTITY % RDF.prefix  "rdf" >
<!ENTITY % RDF.prefixed "INCLUDE">

<!ENTITY % RDF.pfx  "%RDF.prefix;:" >
<!ENTITY % RDF.pfx  "" >

Then a bunch that decide what namespace declaration attributes you
need based on those entities:

<!ENTITY % RDF.xmlns "http://www.w3.org/1999/02/22-rdf-syntax-ns#"

<!ENTITY % RDF.xmlns.attrib
     "xmlns:%RDF.prefix;  %URI.datatype;   #FIXED '%RDF.xmlns;'
<!ENTITY % RDF.xmlns.attrib
     "xmlns        %URI.datatype;          #FIXED '%RDF.xmlns;'

Then a bunch that give the qualified names of the elements in that

<!ENTITY % RDF.RDF.qname  "%RDF.pfx;RDF" >
<!ENTITY % RDF.Description.qname  "%RDF.pfx;Description" >

And you finally use the .qname parameter entities to declare the
elements themselves:

<!ELEMENT %RDF.RDF.qname; (%RDF.Description.qname;*) >

The idea is then that users can define their own prefixes by defining
the %RDF.prefix; and %RDF.prefixed; parameter entities locally within
a document. For example, the above is declared using the 'rdf' prefix
by default; to use no prefix for the RDF namespace, you could do:

<?xml version="1.0"?>
<!DOCTYPE RDF SYSTEM 'rdf.dtd' [
<!ENTITY % RDF.prefix "">
<!ENTITY % RDF.prefixed "IGNORE">
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#">

Obviously this means educating the people writing the XML so that they
know what parameter entities they can set and what effect they have.

Personally, I think that the problem of what happens if the instance
relies on the namespace declaration contained in the DTD is more
serious than the problem of allowing people to use whatever prefix
they want. It would be great if you could declare attributes as being
both fixed and required, but you can't do that with DTDs (though you
can in XML Schema). You need to either educate people to always
include the namespace declaration attribute even though they don't
need to (if it's #FIXED), or educate them to use the correct namespace
within the namespace declaration attribute (if it's #REQUIRED).



Jeni Tennison
Received on Monday, 25 February 2002 07:36:52 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:55:55 UTC