DOM2 Reference

Node.normalize

Source:
  <div id="doc"></div>
JavaScript:
  var main = document.getElementById('doc');
  var output1 = main.childNodes.length;
  var textNode1 = document.createTextNode('This is some text.');
  var textNode2 = document.createTextNode('This is another text.');
  main.appendChild(textNode1);
  main.appendChild(textNode2);
  var output2 = main.childNodes.length;
  main.normalize();
  var output3 = main.childNodes.length;
Output:
desired your browser
output1: 0
output2: 2
output3: 1


Remarks:
  • 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