replaceData Method

MSXML 5.0 SDK

Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - DOM Reference

replaceData Method

Replaces the specified number of characters with the supplied string.

[Script]

Script Syntax

oXMLDOMCharacterData.replaceData(offset, count, data);

Parameters

offset
The long integer value specifying the offset, in characters, at which to start replacing string data.
count
The long integer value specifying the number of characters to replace.
data
The string containing the new data that replaces the old string data.

Example

The following script example creates a new IXMLDOMComment object, and then replaces the first five characters with a new string.

var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.5.0");
var comment;
xmlDoc.async = false;
xmlDoc.load("books.xml");
if (xmlDoc.parseError.errorCode != 0) {
   var myErr = xmlDoc.parseError;
   alert("You have error " + myErr.reason);
} else {
   comment = xmlDoc.createComment("Hello World!");
   alert(comment.xml);
   comment.replaceData(0, 5, "Goodbye, Cruel");
   alert(comment.xml);
}
[Visual Basic]

Visual Basic Syntax

oXMLDOMCharacterData.replaceData(offset, count, data)

Parameters

offset
The long integer value specifying the offset, in characters, at which to start replacing string data.
count
The long integer value specifying the number of characters to replace.
data
The string containing the new data that replaces the old string data.

Example

The following Microsoft® Visual Basic® example creates a new IXMLDOMComment object, and then replaces the first five characters with a new string.

Dim xmlDoc As New Msxml2.DOMDocument50
Dim comment As IXMLDOMComment
xmlDoc.async = False
xmlDoc.Load ("books.xml")
If (xmlDoc.parseError.errorCode <> 0) Then
   Dim myErr
   Set myErr = xmlDoc.parseError
   MsgBox("You have error " & myErr.reason)
Else
   Set comment = xmlDoc.createComment("Hello World!")
   MsgBox comment.xml
   comment.replaceData 0, 5, "Goodbye, Cruel"
   MsgBox comment.xml
End If
[C/C++]

C/C++ Syntax

HRESULT replaceData(
    long offset,
    long count,
    BSTR data);

Parameters

offset [in]
The offset, in characters, at which to start replacing string data.
count [in]
The number of characters to replace.
data [in]
The new data that replaces the old string data.

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.

To view reference information for Visual Basic, C/C++, or Script only, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

Applies to: IXMLDOMCDATASection | IXMLDOMCharacterData | IXMLDOMComment | IXMLDOMText