ADVERTISEMENT
Google AdSense Slot (headerLeaderboard)

Set your Publisher ID in src/config/ads.ts to display live ads.

XML Tutorial• 6 min read

XML Namespaces: Avoiding Element Name Collisions

The xmlns attribute, URI identifiers, and prefixed tag notation

XML Namespaces resolve element naming conflicts when combining vocabularies from different domain schemas by prefixing tags with a unique namespace identifier.

The xmlns Mechanism

A conflict occurs if an HTML <table> (grid layout) and a furniture catalog <table material="wood"> exist in the same document.

Namespaces associate a prefix with a globally unique Uniform Resource Identifier (URI) using xmlns:prefix="URI".

The URI is used solely as a unique string identifier; parsers do not visit the URL on the web.

Resolving Collisions with Namespaces
<root xmlns:h="http://www.w3.org/1999/xhtml"
      xmlns:f="https://codexia.org/furniture">

  <!-- HTML Table element -->
  <h:table>
    <h:tr><h:td>Apples</h:td><h:td>Bananas</h:td></h:tr>
  </h:table>

  <!-- Furniture Table element -->
  <f:table>
    <f:name>African Oak Dining Table</f:name>
    <f:width>180</f:width>
    <f:length>90</f:length>
  </f:table>

</root>
h: and f: prefixes cleanly separate HTML layout from furniture inventory.
ADVERTISEMENT
Google AdSense Slot (inContentBanner)

Set your Publisher ID in src/config/ads.ts to display live ads.

Test Yourself With Exercise

+15 XP

What is the primary purpose of the `xmlns` attribute in an XML document?