Re: Using xml:lang in Schemas

Hi Dan,

> This seems to me to make xml:lang (how about the
> xml:preserve-space?) special XML attribute to be there and available
> by default and that any namespace requirements are automagically
> handled by the parser.

The second part of this (that the 'xml' namespace is automagically
handled by the parser) is true, but the first part (that the XML
attributes are there and available by default) is false.

The XML Namespaces Rec says:

  The prefix xml is by definition bound to the namespace name
  http://www.w3.org/XML/1998/namespace.

                    http://www.w3.org/TR/REC-xml-names/#nsc-NSDeclared
  
which means that you never have to have an
xmlns:xml="http://www.w3.org/XML/1998/namespace" attribute within your
XML document (and I believe that some parsers treat this as saying
that it's an error if you *do* have this namespace declaration).

So don't worry about the fact that you're using the 'xml' prefix
without declaring it -- the mechanism that allows you to do that is
built into XML at a fairly low level.

The XML Rec says:

  A special attribute named xml:lang may be inserted in documents to
  specify the language used in the contents and attribute values of
  any element in an XML document. In valid documents, this attribute,
  like any other, must be declared if it is used.

                             http://www.w3.org/TR/REC-xml#sec-lang-tag

In other words, you can use xml:lang wherever you like in XML
documents and it has a fixed semantics built into the XML Rec, but if
you're checking the validity of a document then you have to explicitly
declare the attribute in the DTD or schema against which you're
validating.

Of course in XML Schema, you don't necessarily have to declare the
fact that you're using xml:lang explicitly -- you could just use a
wildcard instead, such as:

  <xsl:anyAttribute namespace="http://www.w3.org/XML/1998/namespace"
                    processContents="lax" />

which would enable your elements to have any attributes from the XML
namespace. Otherwise, you have to reference xml:lang explicitly and,
because it's in another namespace, you have to import a schema for
that namespace.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

Received on Wednesday, 19 June 2002 06:31:20 UTC