|
The actual use of namespaces, as opposed to the stated reason for their existence and predating XML Schema which has a bad model for this usage of namespaces, is to allow the extensibility of applications with data not understood by a particular application X but understandable by a particular application Y or some developer's homemade script for example. This takes advantage of the general habit of applications targetting various xml dialects of ignoring what they do not understand in an unknown namespace (xhtml, svg, xsl-fo) certainly this could be done without using namespaces but would lead to other problems vis-a-vis validation. Also there are certain xml formats such as XMI or the xml serialization of RDF that can be considered as helper formats, these formats also happen to have names of both elements and attributes that could give rise to name collisions (Description springs immediately to mind), one could get around this problem by making sure one gave all elements and attributes unlikely to be duplicated names, such as RDFDescription but that would just add to the ugliness of syntax in another way than namespaces and would probably lead to confusion from newbies anyway (as in why don't we just call it Description?!?), to get around this problem somebody somewhere would probably then suggest that we need namespaces.
I made the mention of XML Schema because as noted it has a bad model for this usage of namespaces, so as to build extensibility into the validation of xml schema one often uses the any construction at various places, which can be used to associate extensible content with specific namespaces and so forth. This indicates another little useful aspect of namespaces for programming in that namespaces allow one to refer to sets of elements and attributes generically, for example the xpath //html:* would allow you to get all xhtml elements given that you had associated with the namespace, this can of course also be done in other APIs to XML, this is a real time saver. I can think of other ways this could be done, but these ways would be far from trivial, if you can think of a trivial way to do it please point it out, and I should think the way should be described somewhat concretely.
This facility of mixing namespaces is of course very important to the concept of compound documents.
|