Namespace Introduction

  • XML namespaces provide a simple method for qualifying element and attribute names used in Extensible Markup Language documents by associating them with namespaces identified by URI references.

  • Namespace URI

    The namespace value is a URI reference (Uniform Resource Indicator) this does not mean that the resource should be resolvable like a URL.

  • Example:

    We have 2 different XML Vocabularies which can be used together but are using the same element names. XHTML uses the <select>, <submit> and <input> elements to define input controls, however XForms also allows these 2 elements. Namespaces can now be used to distinguish between these elements.

    <html xmlns="" xml:lang="en" lang="en">
        <title>XForms Example</title>
        <model xmlns="">
            <person xmlns="">
          <submission id="form1" method="get" action="submit.asp"/>
        <p>The following is XForms markup:</p>
        <input ref="fname" xmlns="">
          <label>First Name</label>
        <input ref="lname" xmlns="">
          <label>Last Name</label>
        <submit submission="form1" xmlns="">
  • Constraints:

    The prefix xml is by definition bound to the namespace name

    Namespace declarations must be provided either directly or via default attributes declared in the internal subset of the DTD.


    Never use the "default attributes declared in a DTD" mechanism, this makes documents very dependent on the DTD.