Kbase P50586: X-NODEREF:normalize() does not remove whitespace. Should it
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  31/10/2003 |
|
Status: Unverified
GOAL:
What does the NORMALIZE() method actually do? Or how to use the this method?
FIX:
According to the W3C organization 'Document Object Model Core' specifications, (DOM), the NORMALIZE() method puts all Text nodes in the full depth of the sub-tree underneath this Node, including attribute nodes, into a "normal" form where only structure (e.g., elements, comments, processing instructions, CDATA sections, and entity references) separates Text nodes, i.e., there are neither adjacent Text nodes nor empty Text nodes.
When a document is first made available via the DOM, there is only one Text node for each block of text. Users may create adjacent Text nodes that represent the contents of a given element without any intervening markup, but should be aware that there is no way to represent the separations between these nodes in XML or HTML, so they will not (in general) persist between DOM editing sessions. The normalize() method on Node merges any such adjacent Text objects into a single node for each block of text.
The following code illustrates this behavior. Notice that the three text nodes were merged into one text node by the NORMALIZE() method:
DEFINE VARIABLE hDoc AS HANDLE.
DEFINE VARIABLE hRoot AS HANDLE.
DEFINE VARIABLE hText AS HANDLE.
CREATE X-DOCUMENT hDoc.
CREATE X-NODEREF hRoot.
CREATE X-NODEREF hText.
DEFINE VARIABLE i AS INTEGER NO-UNDO.
hDoc:CREATE-NODE(hRoot,"RootName","ELEMENT").
hDoc:APPEND-CHILD(hRoot).
DO i = 1 TO 3:
hDoc:CREATE-NODE(hText, "TextName", "TEXT").
hRoot:APPEND-CHILD(hText).
END.
MESSAGE hRoot:NUM-CHILDREN
VIEW-AS ALERT-BOX INFO BUTTONS OK.
hRoot:NORMALIZE().
MESSAGE hRoot:NUM-CHILDREN
VIEW-AS ALERT-BOX INFO BUTTONS OK.
For more information on the W3C DOM specifications visit:
http://www.w3.org/TR/DOM-Level-2-Core/core.html