Name

insertData: offset, arg

Synopsis

This method takes a string, splits the data attribute’s current contents at the given offset, then inserts the string from the arg parameter between the two substrings.

Arguments

offset: unsigned long

The zero-based offset in the data attribute where the insertion is made.

arg: DOMString

The string to be inserted.

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 insertData(long offset, String arg) throws
  DOMException;

Java example

// Insert data into a string
boolean fCynical = true;
     
// create a new Text object, and reference the CharacterData interface
CharacterData ndCD = doc.createTextNode("The truth is out there.");
     
...
     
// check for cynicism
if (fCynical) {
    ndCD.insertData(12, " not");
}
     
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.