XML Namespaces Andrey Smirnov CSCI 7818 September 21, 2000
Overview Why do we need Namespaces in XML? Definition of Namespace. How do we specify Namespaces? Questions.
Why Namespaces? The purpose of XML Namespaces is to distinguish between duplicate element and attribute names. For example: $ Both “sedans” and “trucks” have the same “price” element, so the parser doesn’t know which one is which.
Definition Namespace is a mapping between an element prefix and a URI –cars is the prefix in this example, –URIs are not a pointer to information about the Namespace. They are just unique identifiers. You cannot resolve XML namespace URIs.
Ways to Specify Namespaces Inside the XML file. Inside the DTD file.
XML File Specify a Namespace for every element.
XML File Specify all Namespaces within the root element. The specification given for the that element is also valid for all elements occurring inside it.
XML File Namespaces do not have to be specified explicitly with prefixes. The attribute xmlns defines the default namespace which is used for the element.
XML File Attributes can be explicitly assigned a value and be associated with a Namespace by using prefixes.
XML File Attributes without a prefix do not belong to any Namespace.
XML File A Namespace specification can be overridden using the prefixes. It’s uppercase now.
DTD File Here is a sample Namespace specification within a DTD. <!ATTLIST cars xmlns:part CDATA #FIXED “
Questions Any questions? Any comments?