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

Re: Using xml:lang in Schemas

From: Jeni Tennison <jeni@jenitennison.com>
Date: Tue, 23 Jul 2002 11:15:42 +0100
Message-ID: <1961463469818.20020723111542@jenitennison.com>
To: Ian Stokes-Rees <ijs@decisionsoft.com>
CC: "Henry S. Thompson" <ht@cogsci.ed.ac.uk>, Danny Vint <dvint@mindspring.com>, <xmlschema-dev@w3.org>

Hi Ian,

> Are there special rules which _only_ allow the "xml" prefix to be
> bound to the "XML Namespace" namespace?

In effect, yes. The 'xml' prefix is *by definition* bound to the XML
namespace, and you're not allowed to declare a namespace with a prefix
beginning with 'xml' yourself [1].

> Conversely, are there special rules which state that the XML
> namespace _can_only_ be bound to the "xml" prefix?

No, there's no rule like that. You can associate the XML namespace
with whatever prefix you like.

> By way of example:
> <foo
> xmlns="http://www.example.com/default_namespace"
> xmlns:xml="http://www.w3.org/XML/1998/namespace"
> xmlns:aaa="http://www.w3.org/XML/1998/namespace"
> xmlns:bbb="http://www.example.com/another_namespace" >
>   <bar xml:lang="en" />
>   <baz aaa:lang="en" />
>   <bang bbb:lang="1234" />
> </foo>
> Presumably the <bar> and <bang> elements are acceptable. How does
> the schema for "http://www.example.com/default_namespace" come into
> this?
> Does it need to explicitly allow xml:lang and bbb:lang attributes on
> the <bar> and <bang> elements respectively?

Yes. The xml:lang attribute is exactly like any other attribute in
terms of whether it needs to be defined in a schema (or DTD) in order
to be valid in an instance document [2]. The only thing that's really
special about the xml:lang attribute is that its semantics are defined
in the XML Recommendation, which means that you can be fairly sure
that it means the same thing (it describes the language of the content
of the elements in its scope) whenever it's used. Conversely, we have
no idea what bbb:lang might mean.

> Is the declaration of "http://www.w3.org/XML/1998/namespace"
> unnecessary because it would have been declared in the schema for
> the default namespace?

A declaration associating 'xml' with the namespace
'http://www.w3.org/XML/1998/namespace' is always unnecessary because
it is present in every XML document by definition [3].

> Is there any way to add "xml:lang" attributes to an element even if
> they are not explicitly permitted by the schema?

Of course. You can add any attribute to any element, or add any
content to any element even if it's not explicitly permitted by the
schema. You would still have a well-formed XML document. It just
wouldn't be valid against the schema. If you mean can you add an
"xml:lang" attribute to an element on which it isn't declared *and
still have a valid document*, then the answer is no.

> I recall reading somewhere that explicitly namespaced attributes
> could exist on elements even if they were not declared as part of
> the parent elements schema definition of the content model. Is this
> inaccurate (or am I imagining this)?

Either what you read was inaccurate or you imagined it. Declaring an
attribute globally doesn't make it available on every element in the
document. However, declaring an attribute globally does mean that a
complex type can *refer* to that attribute declaration, such that you
get a common attribute declaration in use on many elements.

> Looking at the schema http://www.w3.org/2001/xml.xsd continues to
> confuse me as there are references to xml:lang without the xml
> prefix being declared anywhere. Obviously there are things here in
> the way namespaces, schemas, xml:lang, the "xml" character sequence,
> and namespace prefix binding work that I don't understand and I
> would certainly appreciate some clarification.

In essence, there's a built-in namespace declaration associating the
prefix 'xml' with the namespace
'http://www.w3.org/XML/1998/namespace', so you never need to have that
declaration present in an XML document. Aside from that, however,
'xml:lang' and the rest of the xml:* attributes are just like normal



[1] http://www.w3.org/TR/REC-xml-names/#xmlReserved
[2] http://www.w3.org/TR/REC-xml#sec-lang-tag
[3] http://www.w3.org/TR/REC-xml-names/#nsc-NSDeclared

Jeni Tennison
Received on Tuesday, 23 July 2002 06:15:43 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 23:15:04 UTC