XML Namespaces (jmenné prostory)

  • XML Namespaces (W3C Recommendation, currently Namespaces in XML 1.0 (Third Edition) W3C Recommendation 8 Dec 2009): http://www.w3.org/TR/REC-xml-names

  • to new XML, there exists Namespaces in XML 1.1 W3C Recommendation (Second Edition) 16 August 2006. Andrew Layman, Richard Tobin, Tim Bray, Dave Hollander

  • They define logical spaces for names of elements, attributes in XML document.

XML Namespaces (jmenné prostory)

  • They give the elements and attributes the "third dimension".

  • To each NS in XML, there is exactly one ("globally") unique identifier, given by URI (URIs is a superset of URLs).

  • NS corresponding to an URI does not anyhow relate to content that would potentially be available under the URL ("nothing is downloaded when processing NSs".

Prefixes and Equivalence of NSs (1)

  • Instead of URIs for denoting a namespace in document, one uses prefixes for these NS mapped to the respective URI using xmlns:prefix="URI".

  • Element- or attribute-name containing colon (:) is denoted as Qualified Name, QName.

Prefixes and Equivalence of NSs (2)

  • Two NS are equal iff their URIs are one-to-one-character the same (in UNICODE).

  • Namespaces do not apply to text nodes.

  • Element/attribute need not be in a namespace.

Prefixes and Equivalence of NSs (3)

  • NS prefix declaration or declaration or the implicit NS recursively applies to all descendants (child elements, their children etc.), unless another declaration "remaps" the given prefix.

  • One NS is co-called implicit (default) NS, declared by attribute xmlns=

  • Default NSs are NOT applied to attributes!!!, thus attributes without an explicit prefix do not belong to any NS.

Example 1. Default NS

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <body>
     <h1>Huraaaa</h1>
  </body>
</html>

Example 2. Prefixed NS

<xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <xhtml:body>
     <xhtml:h1>Huraaaa</xhtml:h1>
  </xhtml:body>
</xhtml:html>
  • NS are not compatible with DTD.

  • DTD strictly differentiates between eg. name xi:include and include even if they belong to the same NS and should thus have the same interpretation/meaning for applications.