DOM2 Reference

NamedNodeMap.setNamedItemNS

Text in the first DIV.
x a b x
Text in the last DIV.
Source:
       <div id="doc" xmlns:svg="http://www.w3.org/2000/svg">
         <div>
           Text in the first DIV.
         </div>
         <svg:svg id="logo" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="60">
           <svg:g style="fill:#3399cc; font-size:36pt; font-family:'dialog'; font-weight: bold">
             <svg:a xlink:type="simple" xlink:href="http://www.zvon.org">
               <svg:text x="50%" y="65%" text-anchor="middle">ZVON.org</svg:text>
             </svg:a>
           </svg:g>
         </svg:svg>
         <apply xmlns="http://www.w3.org/1998/Math/MathML">
	   <int/> 
	   <bvar> 
	     <ci> x </ci> 
	   </bvar> 
	   <interval> 
	     <ci> a </ci> 
	     <ci> b </ci> 
	   </interval> 
	   <apply>
	     <cos/> 
	     <ci> x </ci> 
	   </apply> 
         </apply> 
         <div>
           Text in the last DIV.
         </div>
       </div>
     
JavaScript:
  var attrNode = document.getElementById('doc').attributes;
  var attr = document.createAttributeNS('http://zvon.org/namespaces/test', 'zvon:temp');
  attr.value = 'temporary';
  attrNode.setNamedItemNS(attr);
  var output = attrNode.getNamedItemNS('http://zvon.org/namespaces/test', 'zvon:temp').nodeValue;
Output:
desired your browser
temporary


Remarks:
  • remember that all namespace examples are here only to provide starting point for discussion and other work because specification is not very clear sometimes and there is probably no way to test examples right now
  • it seems that all relevant browsers support JavaScript try-catch statement therefore all examples are encapsulated with it (it avoids alert-popups)
  • thanks to White Space Handling in XML 1.0 specification default handling of white-spaces completely depends on XML application (note: WinIE do not preserve white-spaces by default while MacIE and Mozilla does)
  • during development tested with Mozilla night-builds, Netscape6, MicrosoftInternetExplorer5.5 and Opera5.02 on Windows2000



_____________________________________________
Reference Search | Sitemap | XML Glossary       ZVON | IDOOX