Splits this text node into two text nodes at the specified offset and inserts the new text node into the tree as a sibling that immediately follows this node.
var objXMLDOMText = oXMLDOMText.splitText(offset);
An object. Returns the new text node.
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.5.0"); var nodeRoot, nodeText, newNodeText; xmlDoc.async = false; xmlDoc.loadXML("<root>Hello World!</root>"); if (xmlDoc.parseError.errorCode <> 0) { var myErr = xmlDoc.parseError; alert("You have error " + myErr.reason); } else { nodeRoot = xmlDoc.documentElement; nodeText = nodeRoot.firstChild; alert(nodeRoot.childNodes.length); newNodeText = nodeText.splitText(6); alert(nodeRoot.childNodes.length); }
Set objXMLDOMText = oXMLDOMText.splitText(offset)
An object. Returns the new text node.
Dim xmlDoc As New Msxml2.DOMDocument50 Dim nodeRoot As IXMLDOMElement Dim nodeText As IXMLDOMText Dim newNodeText As IXMLDOMText xmlDoc.async = False xmlDoc.loadXML "<root>Hello World!</root>" If (xmlDoc.parseError.errorCode <> 0) Then Dim myErr Set myErr = xmlDoc.parseError MsgBox("You have error " & myErr.reason) Else Set nodeRoot = xmlDoc.documentElement Set nodeText = nodeRoot.firstChild MsgBox nodeRoot.childNodes.length Set newNodeText = nodeText.splitText(6) MsgBox nodeRoot.childNodes.length End If
HRESULT splitText( long offset, IXMLDOMText **rightHandTextNode);
IXMLDOMText *pIXMLDOMTextTemp = NULL; IXMLDOMText *pIXMLDOMText = NULL; IXMLDOMNode *pIXMLDOMNodeTemp = NULL; IXMLDOMElement *pIXMLDOMElement = NULL; IXMLDOMNode *pIXMLDOMNode = NULL; DOMNodeType DOMNodeTyp; VARIANT varValue; 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->QueryInterface(IID_IXMLDOMNode, (void **)&pIXMLDOMNode); SUCCEEDED(hr) ? 0 : throw hr; pIXMLDOMElement->Release(); pIXMLDOMElement = NULL; while(pIXMLDOMNode) { hr = pIXMLDOMNode->get_nodeType(&DOMNodeTyp); if(SUCCEEDED ( hr) && (DOMNodeTyp == NODE_TEXT)) { hr = pIXMLDOMNode->QueryInterface(IID_IXMLDOMText, (void**)&pIXMLDOMText); SUCCEEDED(hr) ? 0 : throw hr; if(pIXMLDOMText) { hr = pIXMLDOMText->splitText(2, &pIXMLDOMTextTemp); if(SUCCEEDED(hr) && pIXMLDOMTextTemp) { hr = pIXMLDOMTextTemp->get_nodeValue(&varValue); if(SUCCEEDED(hr)) ::MessageBox(NULL, _bstr_t(varValue), _T("Notation Public ID"), MB_OK); pIXMLDOMTextTemp->Release(); pIXMLDOMTextTemp = NULL; } pIXMLDOMText->Release(); pIXMLDOMText = NULL; } pIXMLDOMNode->Release(); pIXMLDOMNode = NULL; break; } pIXMLDOMNode->get_firstChild(&pIXMLDOMNodeTemp); pIXMLDOMNode->Release(); pIXMLDOMNode = pIXMLDOMNodeTemp; pIXMLDOMNodeTemp = NULL; } } } catch(...) { if(pIXMLDOMNodeTemp) pIXMLDOMNodeTemp->Release(); if(pIXMLDOMNode) pIXMLDOMNode->Release(); if(pIXMLDOMTextTemp) pIXMLDOMTextTemp->Release(); if(pIXMLDOMText) pIXMLDOMText->Release(); if(pIXMLDOMElement) pIXMLDOMElement->Release(); DisplayErrorToUser(); } // Release pIXMLDOMDocument when finished with it.
If you specify an offset of zero, the first text node is empty and the right-hand text node contains the previous contents of the node. If you specify an offset beyond the end of the string, a new, empty right-hand text node is created.
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: IXMLDOMCDATASection | IXMLDOMText