splitText Method
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.
[Script]
Script Syntax
var objXMLDOMText = oXMLDOMText.splitText(offset);
Parameters
- offset
- A long integer. The number of characters at which to split this text node into two nodes, starting from zero.
Return Value
An object. Returns the new text node.
Example
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); }
[Visual Basic]
Visual Basic Syntax
Set objXMLDOMText = oXMLDOMText.splitText(offset)
Parameters
- offset
- A long integer. The number of characters at which to split this text node into two nodes, starting from zero.
Return Value
An object. Returns the new text node.
Example
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
[C/C++]
C/C++ Syntax
HRESULT splitText( long offset, IXMLDOMText **rightHandTextNode);
Parameters
- offset [in]
- The number of characters at which to split this text node into two nodes, starting from zero.
- rightHandTextNode [out, retval]
- The new text node.
C/C++ Return Values
- S_OK
- The value returned if successful.
- S_FALSE
- The value when returning Null.
- E_FAIL
- The value returned if an error occurs.
C/C++ Example
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.
Remarks
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.
See Also
Applies to: IXMLDOMCDATASection | IXMLDOMText