Name

replaceData: offset, count, arg

Synopsis

This replaces a substring within the data attribute with another string value arg, using the specified offset and count parameters.

Arguments

offset: long

The offset of the beginning of the replacement region.

count: long

The number of characters to replace. If offset + count is >= the length attribute, everything beyond the offset character position is replaced.

arg: DOMString

The replacement string.

The replaceData operation is the equivalent of the following code fragment:

cdNode.deleteData(offset, count);
cdNode.insertData(offset, arg);

Exceptions

INDEX_SIZE_ERR

Raised if the offset parameter is not a valid, zero-based index into the data DOMString.

NO_MODIFICATION_ALLOWED_ERR

Raised if the node is read-only.

Java binding

public void replaceData(long offset, long count,
                        String arg) throws DOMException;

Java example

 // Create a new Text object and reference the CharacterData interface
CharacterData ndCD = doc.createTextNode("The truth is not out there.");
     
// replace the truth
String strFind = "truth";
String strReplace = "dog";
    
ndCD.replaceData(ndCD.getData( ).indexOf(strFind), strFind.length( ), 
                 strReplace);
     
System.out.println(ndCD.getData( ));

Get XML in a Nutshell, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.