faqts : Computers : Programming : Languages : JavaScript : XML : E4X (ECMAScript for XML) : XML objects

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

Entry

How do I use the method normalize?
How do I use the method normalize?

Apr 11th, 2005 04:40
Martin Honnen,


The method normalize takes no argument and returns the XML object it is
called on after normalizing all text content so that adjacent text nodes
are merged into one text node and empty text nodes are removed.
Note that after the initial parsing any XML object should be normalized,
only if later manipulation repeatedly inserts text it can happen that
there are adjacent text nodes so that text is not normalized.
Here is an example:
  var text = <text xml:lang="en">Initial text. Initial Text.</text>;
  alert(text.*.length()); // shows 1
  for (var i = 1; i <= 5; i++) {
    text.appendChild(new XML('Text node ' + i + '.'));
  }
  alert(text.*.length()); // shows 6;
  text.normalize();
  alert(text.*.length()); // shows 1