Click to return to the XML (Extensible Markup Language) home page    
Object Model Support     Parsing Support     Introduction to Namespace...    
Web Workshop  |  XML (Extensible Markup Language)

Namespace Scope


Namespace declarations are scoped using an element container. In the default declaration example, all unqualified elements (without explicit namespace on the element) within the "BOOK" element belong to the "urn:BookLovers.org:BookInfo" namespace. In the following example, notice that all unqualified elements within the "table" element are scoped to the default namespace "http://www.w3.org/TR/REC-html40". On the "details" tag, the default namespace is set to "urn:beerstuff.org:brandinfo". All unqualified tags within the "details" element are scoped to this namespace.

<Beers>
  <!-- the default namespace is now that of HTML -->
  <table xmlns="http://www.w3.org/TR/REC-html40">
    <tr><td>Name</td><td>Origin</td><td>Description</td></tr>
    <tr>
      <!-- drop the HTML namespace inside table cells -->
      <td><brandName xmlns="urn:beerstuff.org:brandinfo">Huntsman</brandName></td>
      <td><origin xmlns="urn:beerstuff.org:brandinfo">Bath, UK</origin></td>
      <td>
        <details xmlns="urn:beerstuff.org:brandinfo">
          <class>Bitter</class>
          <hop>Fuggles</hop>
          <pro>Wonderful hop, light alcohol, good summer beer</pro>
          <con>Fragile; excessive variance pub to pub</con>
        </details>
      </td>
    </tr>
  </table>
</Beers>

The following table shows the elements and attributes of the above XML example and their properties within the XML object model.

Node typenodeNamenamespaceURIprefixbaseName
ELEMENTBeersBeers
ELEMENTtablehttp://www.w3.org/TR/REC-html40table
ATTRIBUTExmlnsxmlns
ELEMENTtrhttp://www.w3.org/TR/REC-html40tr
ELEMENTtdhttp://www.w3.org/TR/REC-html40td
ELEMENTtdhttp://www.w3.org/TR/REC-html40td
ELEMENTtdhttp://www.w3.org/TR/REC-html40td
ELEMENTtrhttp://www.w3.org/TR/REC-html40tr
ELEMENTtdhttp://www.w3.org/TR/REC-html40td
ELEMENTbrandNameurn:beerstuff.org:brandinfobrandName
ATTRIBUTExmlnsxmlns
ELEMENTtdhttp://www.w3.org/TR/REC-html40td
ELEMENToriginurn:beerstuff.org:brandinfoorigin
ATTRIBUTExmlnsxmlns
ELEMENTtdhttp://www.w3.org/TR/REC-html40td
ELEMENTdetailsurn:beerstuff.org:brandinfodetails
ATTRIBUTExmlnsxmlns
ELEMENTclassurn:beerstuff.org:brandinfoclass
ELEMENThopurn:beerstuff.org:brandinfohop
ELEMENTprourn:beerstuff.org:brandinfopro
ELEMENTconurn:beerstuff.org:brandinfocon

The namespace shorthands are valid within the element in which they are defined. In the explicit declaration example, the shorthands "bk" and "money" are valid only within the "bk:BOOK" element.



Back to topBack to top

Did you find this topic useful? Suggestions for other topics? Write us!

© 1999 Microsoft Corporation. All rights reserved. Terms of use.