HTML 4.01 strict HTML

This page contains the XML for <SCRIPT> DOMText object documentation.

Return to W3C DOM Parser Documentation Main Page

NOTE: DOMText descends from DOMCharacterData and inherits all of the properties and methods of the DOMCharacterData object

DOMText - object description
Native Methods:
DOMText - splitText method
Inherited Methods:
DOMCharacterData - getData method
DOMCharacterData - setData method
DOMCharacterData - getLength method
DOMCharacterData - substringData method
DOMCharacterData - appendData method
DOMCharacterData - insertData method
DOMCharacterData - deleteData method
DOMCharacterData - replaceData method
DOMNode - getNodeName method
DOMNode - getNodeValue method
DOMNode - setNodeValue method
DOMNode - getNodeType method
DOMNode - getParentNode method
DOMNode - getChildNodes method
DOMNode - getFirstChild method
DOMNode - getLastChild method
DOMNode - getPreviousSibling method
DOMNode - getNextSibling method
DOMNode - getAttributes method
DOMNode - getNamespaceURI method
DOMNode - getPrefix method
DOMNode - getLocalName method
DOMNode - getOwnerDocument method
DOMNode - insertBefore method
DOMNode - replaceChild method
DOMNode - removeChild method
DOMNode - appendChild method
DOMNode - hasChildNodes method
DOMNode - cloneNode method
DOMNode - getElementsByTagName method
DOMNode - getElementsByTagNameNS method
DOMNode - setPrefix method
DOMNode - normalize method
DOMNode - isSupported method
DOMNode - getXML method
DOMNode - hasAttributes method
DOMText - object description

The DOMText interface inherits from DOMCharacterData and represents the textual content (termed character data in XML) of a DOMElement or DOMAttr. If there is no markup inside an element's content, the text is contained in a single object implementing the DOMText interface that is the only child of the element. If there is markup, it is parsed into the information items (elements, comments, etc.) and DOMText nodes that form the list of children of the element.

When a document is first made available via the DOM, there is only one Text node for each block of text. Users may create adjacent Text nodes that represent the contents of a given element without any intervening markup, but should be aware that there is no way to represent the separations between these nodes in XML, so they will not (in general) persist between DOM editing sessions. The normalize() method on DOMNode merges any such adjacent DOMText objects into a single node for each block of text.

DOMText - splitText method
W3C DOM Level 1


int offset - zero based offset where the node will be split into two nodes

DOMNode - The newly created DOMText node

DOMException.NO_MODIFICATION_ALLOWED_ERR - Thrown if the DOMText is read only
DOMException.INDEX_SIZE_ERR - Thrown if the offset is negative or too large

The splitText method breaks a DOMText node into two nodes at the specified offset, keeping both in the tree as siblings. After being split, the original node will contain all the content up to the offset point. A new node of the same type, which contains all the content at and after the offset point, is returned. If the original node had a parent node, the new node is inserted as the next sibling of the original node. When the offset is equal to the length of this node, the new node has no data.

function xmljsDOMExample() {
var xml;
xml = ""
+ "<?xml version=\"1.0\"?>"
+ "<ROOT>"
+ "<TAG1>"
+ "Hello World"
+ "<![CDATA[Foo Foobar]]>"
+ "</TAG1>"
+ "</ROOT>";

//instantiate the W3C DOM Parser
var parser = new DOMImplementation();

//load the XML into the parser and get the DOMDocument
var domDoc = parser.loadXML(xml);

//get the document root
var docRoot = domDoc.getDocumentElement();

//get the TAG1 node
var tag1 = docRoot.getFirstChild();

//get the "Hello World" text
var textNode = tag1.getFirstChild();

//the following should be 2

//split "Hello World" into two DOMText nodes
//(both of which will be in the tree)

//the following should be 3

//the following should be "Hello "

//the following should be "World"

//get the CDATA section
var cdataNode = tag1.getChildNodes().item(2);

//split "Foo Foobar" into two DOMCDATASection nodes

//NOTE: getXML() serializes text nodes. This means
//that in serialized form, the "Hello " and "World"
//text nodes are not visible as individual nodes
//the following should be
//Hello World
//<![CDATA[ Foobar]]>

}// end function xmljsDOMExample