Is xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" a special case in XML? Is xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" a special case in XML? xml xml

Is xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" a special case in XML?


How do XML parsers know how to handle this namespace?

They don't, except when they do. The basic idea is that the string 'http://www.w3.org/2001/XMLSchema-instance' works like a magic cookie. Either the processing software has been programmed to recognize it, and thus act on the basis of what it means, or it has not.

Thus, with the mere fact of recognition also comes the "knowledge" of what it represents: a "namespace" that defines four attributes ('type', 'nil', 'schemaLocation' and 'noNamespaceSchemaLocation') with fixed predefined meanings.

In other words, if you "know" what the string 'http://www.w3.org/2001/XMLSchema-instance' "means", then you also automatically know what an attribute named xsi:schemaLocation "means": that it points to schema documents encoded in the 'W3C XML Schema' formalism.

This goes beyond what the XML Namespaces Rec actually provides for (which is only some handwaving about "universal names" or whatnot). A convention is at work here, that the syntax of namespacing (using colonified names) has been deployed to hard-code a semantic understanding: "where to find the schema, in the formalism of W3C XML Schemas, for this document instance." It all hinges on prior understanding of that magic cookie string.

You may be under the impression that a namespace must have a schema, and a machine processable one at that, and only in the W3C XML Schemas formalism to boot. None of these are necessarily true. Other schema formalisms exist (SGML/XML DTDs, Relax-NG, both of which, unlike W3C XML Schemas, are international standards); a namespace definition does not have to be machine-readable (it could be prose, as in fact it is for the 'http://www.w3.org/2001/XMLSchema-instance' namespace!); and a namespace need not be formally defined at all, because all a namespace string is guaranteed to do is to function as a disambiguation marker.


There's no requirement to say where the schema is located. You can do it if you want, but you don't have to.

In this example, all platforms are likely to understand where the schemas for xsi, xml, xsd and soap are all located.


EDIT: Like I said, all platforms are likely to know where the schemas are for these well-known namespaces. Quite likely, they all have copies of the schemas. I use Visual Studio, and it keeps copies of these schemas online, and refers to them as necessary.


There are four built in declarations for Xml schemata; type, nil, schemaLocation and noNamespaceSchemaLocation as are "present in every schema by definition." You can read about them in the Xml Schema recommendation.