XML namespacesFrom MozillaZine Knowledge Base(Difference between revisions)
Revision as of 16:18, 4 February 2005[edit] XML namespacesXML namespaces provide a way to distinguish duplicate element and attribute names. Duplicates can occur when an XML document contains elements and attributes from two or more different XML schemas (or DTDs).
<ihoss:some-element xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:ihoss="ihoss-is-cool"> <xul:textbox id="foo" value="bar"/> <ihoss:textbox favorite-food="pancakes"/> </ihoss:some-element>
<window id="foo" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> ... ... </window> and in XHTML documents, you'll see this: <html xmlns="http://www.w3.org/1999/xhtml"> ... ... </html> There is a very subtle difference here than before. Before I wrote xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" but here the :xul piece is omitted. This signifies to the XML parser that http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul is the default namespace for the document, and that any element or attribute without a namespace (i.e., no prefixed colon) belongs to the default namespace. That's why we can write the shorthand <textbox/> instead of <xul:textbox/> all the time (although the latter is just as correct when not using http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul as the default namespace). So, in other words, a default namespace permits a kind of short-hand to be used throughout the document. |