spacer
Yehuda Shiran June 25, 2000
The namespaces Collection
Tips: June 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

Now that XML namespaces are part of HTML Components, Internet Explorer 5.5+ provides a lot of objects, methods, and properties to access these namespaces. XML namespaces is a collection that belongs to the document object. The collection itself is an array object:

oNameSpaceArray = document.namespaces;

To get to a particular namespace object, you can use simple indexing:

oNameSpace = document.namespace[index];

where index starts from 0. You can use string indexing as well. If two namespaces have the same ID or NAME, another integer differentiator is needed:

oNameSpace = document.namespace(sIndex, iSecondary);

The following example uses two namespaces, DOCJS and WEBREF. When we call document.namespace(0) from within the script below, we get the first namespace, DOCJS, as expected.

<HTML XMLNS:DOCJS XMLNS:WEBREF>
<HEAD>
<STYLE>
  @media all {
    DOCJS\:RIGHT {text-align:right; width:100}
  }
</STYLE>
</HEAD>
<BODY>
<DOCJS:RIGHT>
 Read Doc JavaScript's columns, tips, tools, and tutorials
</DOCJS:RIGHT>
<SCRIPT>
  a1 = document.namespaces(0);
  alert(a1.name);
</SCRIPT>
</BODY>
</HTML>


People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business