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.
JScript 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.6.0");
var nodeRoot, nodeText, newNodeText;
xmlDoc.async = false;
xmlDoc.loadXML("<root>Hello World!</root>");
if (xmlDoc.parseError.errorCode != 0) {
var myErr = xmlDoc.parseError;
WScript.Echo("You have error " + myErr.reason);
} else {
nodeRoot = xmlDoc.documentElement;
nodeText = nodeRoot.firstChild;
WScript.Echo(nodeRoot.childNodes.length);
newNodeText = nodeText.splitText(6);
WScript.Echo(nodeRoot.childNodes.length);
}
Output
1
2
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.
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.
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.
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 a negative offset or an offset greater than the length of the first text node, it will return Invalid Argument error. If you specify an offset equal to the length of the first text node, it will return a NULL text node but not insert it into the DOM tree. If you specify an offset of zero and the first text node is not empty the first text node becomes empty and the right hand text node contains the previous contents of the node.
Versioning
Implemented in: MSXML 3.0 and MSXML 6.0