Normalizes all descendant elements by combining two or more adjacent text nodes into one unified text node.
oXMLDOMElement.normalize();
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.5.0"); var nodeRoot; xmlDoc.async = false; xmlDoc.loadXML("<root/>"); if (xmlDoc.parseError.errorCode <> 0) { var myErr = xmlDoc.parseError; alert("You have error " + myErr.reason); } else { nodeRoot = xmlDoc.documentElement; nodeRoot.appendChild(xmlDoc.createTextNode("Hello ")); nodeRoot.appendChild(xmlDoc.createTextNode("World")); nodeRoot.appendChild(xmlDoc.createTextNode("!")); alert(nodeRoot.childNodes.length); nodeRoot.normalize(); alert(nodeRoot.childNodes.length); }
oXMLDOMElement.normalize
Dim xmlDoc As New Msxml2.DOMDocument50 Dim nodeRoot As IXMLDOMElement xmlDoc.async = False xmlDoc.loadXML "<root/>" If (xmlDoc.parseError.errorCode <> 0) Then Dim myErr Set myErr = xmlDoc.parseError MsgBox("You have error " & myErr.reason) Else Set nodeRoot = xmlDoc.documentElement nodeRoot.appendChild xmlDoc.createTextNode("Hello ") nodeRoot.appendChild xmlDoc.createTextNode("World") nodeRoot.appendChild xmlDoc.createTextNode("!") MsgBox nodeRoot.childNodes.length nodeRoot.normalize MsgBox nodeRoot.childNodes.length End If
HRESULT normalize(void);
BOOL DOMElementNormalize() { BOOL bResult = FALSE; IXMLDOMElement *pIXMLDOMElement = NULL; IXMLDOMDocument *pIXMLDOMDocument = NULL; HRESULT hr; try { // Create an instance of DOMDocument and initialize // pIXMLDOMDocument. // Load/create an XML fragment. hr = pIXMLDOMDocument->get_documentElement(&pIXMLDOMElement); SUCCEEDED(hr) ? 0 : throw hr; if(pIXMLDOMElement ) { hr = pIXMLDOMElement->normalize(); if(SUCCEEDED(m_hr)) bResult = TRUE; pIXMLDOMElement->Release(); } } catch(...) { if(pIXMLDOMElement) pIXMLDOMElement->Release(); DisplayErrorToUser(); } return bResult; }
This method converts all text node descendants of this element (at any depth) into a "normal" form where no text nodes are adjacent. In normal form, text nodes can be separated only by markup, such as tags, comments, processing instructions, CDATA sections, and entity references. The normal form is useful for operations that require a particular document tree structure and ensures that the XML Document Object Model (DOM) view of a document is identical when saved and reloaded.
Collapsed node objects are deleted automatically.
To view reference information for Visual Basic, C/C++, or Script only, click the Language Filter button in the upper-left corner of the page.
Applies to: IXMLDOMElement