Whitespace in schemaLocation Value and an Old Bug
By Cheng Fang on Apr 14, 2006
Althoug schemaLocation attribute is not the key, I still like to have it my xml files for completeness/usefulness. I always copy it from some golden files, since I know I will never type it correctly. The format of schemaLocation attribute value is worth special attention:
attribute value consists of one or more pairs of URI references,
separated by white space. The first member of each pair is a namespace
name, and the second member of the pair is a hint describing where to
find an appropriate schema document for that namespace.
So the first part is the namespace value, and doesn't have to be a URL; the second part is the URI of the schema file. For example,
Since we usually use a URL as namespace value, so 99% of the time, the schemaLocation values appear to be pairs of URL's, and people tend to think so.
Another misconception is that schemaLocation value was a single URL. I remember years ago there was a bug that basically says, in some xml files the values of schemaLocation erroneously contain whitespace where a "/" should have been used.
I can't help wondering why schemaLocation value has to be so verbose and confusing, besides historical reasons? I'm no xml expert, but at least two alternatives I can think of:
1. Merge schemaLocation attribute with xmlns attribute. Since schemaLocation is all about 1:1 mapping between namespace and URI, it doesn't make much sense for me to bind them with a separate attribute. For example, the above example xml using merged attributes would be like:
This way we make xmlns value to be a pair, with an optional second part.
2. Preserve schemaLocation attribute, but use the alias name of the namespaces as the first pair, use = between first and second part, and " " to delimit pairs. Since the default namespace doesn't have an alias, we could use . as its alias. We could also require that all namespace attributes should be parsed before schemaLocation attrbute. For example:
This appears more readable and understandable, at least for me. Xml files are not only for machines, but also for human readers. Years ago when people were debating between xml and old-style EDI, xml proponents used to say, look, xml files are human readable.
Here are more resources on XML Namespace.
technorati tags: schemaLocation