Quick References
      ADO
      ASP
      CSS2
      HTML
      JavaScript
      Jet SQL
      VBScript
      WML
      WMLScript
      WSH
      XHTML
      XML DOM
      XSLT

Features
      Knowledge Base
      Tutorials

Partners
     ZVON.ORG
     XML
     Planet Source Code
     VisualBuilder
     Web Design
     Your HTML Source
     XML/XSLT Forums
     ASPAlliance
     Scripts
     
     Programmers Heaven
     Tek-Tips Forums
     Developer Fusion
     Code Project











METHOD:  Element::normalize

Element.normalize( )

The normalize method normalizes all subtree Text nodes, i.e., it combines two or more adjacent ones into a single one. In 'normal' form, text nodes can only be separated by markup such as tags, comments, processing instructions, CDATA sections and entity references. This form is useful for operations requiring a particular document structure, and ensures that the DOM view of the document remains the same when saved and reloaded.

In the following example we load the 'albums.xml' file and append a Text Node to the existing child node of the 'title' element of the third album. (The code displays the number of child nodes to confirm that there are now 2.) Then we call the normalize method and count the number of child nodes again. Finally we display the combined content of the one remaining, normalized child node.

XML:
<Albums>
   <Album ref="CD142" category="Folk">
      <title>Boil The Breakfast Early</title>
      <artist>The Chieftains</artist>
   </Album>
   <Album ref="CD720" category="Pop">
      <title>Come On Over</title>
      <artist>Shania Twain</artist>
   </Album>
   <Album ref="CD024" category="Country">
      <title>Red Dirt Girl</title>
      <artist>Emmylou Harris</artist>
   </Album>
</Albums>

Code (VBScript):
Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.load("albums.xml")

Set Elem = objXMLDoc.documentElement.childNodes.item(2).firstChild
Set Text = objXMLDoc.createTextNode("Move along, nothing to see here.")
Elem.appendChild(Text)
numChildren = Elem.childNodes.length
document.write ("Number of child nodes: " & numChildren)

Elem.normalize
numChildren = Elem.childNodes.length
document.write ("<br>child nodes after normalization: " & numChildren)
document.write("<br>" & Elem.firstChild.nodeValue)

Output:
Number of child nodes: 2
child nodes after normalization: 1
Red Dirt GirlMove along, nothing to see here.



 


Copyright 1999-2005 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information