The CharacterData object is not really a DOM object as such, but rather extends the Node object with various properties and methods for manipulating text. These are capable of handling very large amounts of text (amounts beyond the scope of native string functions) and can be implemented by the CDATASection, Comment and Text Nodes. To demonstrate a few of the properties and methods of CharacterData the following code loads the 'currencies.xml' file and displays information about the first 'currency' element using the data and length properties. It then gets a substring of the text using the substringData method and displays that.
XML:
<currencies>
<currency>CHF Swiss Francs</currency>
<currency>DEM German Deutsche Marks</currency>
<currency>GBP United Kingdom Pounds</currency>
<currency>JPY Japanese Yen</currency>
<currency>USD United States Dollars</currency>
</currencies>
VBScript:
Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.load("currencies.xml")
Set Elem = objXMLDoc.documentElement.firstChild
Set Text = Elem.firstChild
document.write(Text.data)
document.write("<br>length: " & Text.length)
Substr = Text.substringData(4, 5)
document.write("<br>" & Substr)
CHF Swiss Francs
length: 16
Swiss
Syntax: node.attributes
This is a read-only property that returns a NamedNodeMap for nodes that can have attributes.
Syntax: document.basename
This is a read-only property that returns the base name for a node.
Syntax: node.childNodes
This is a read-only property containing a node list of all children for those elements that can have them.
Syntax: characterData.data
This property contains the data for this node, depending on node type.
Syntax: node.dataType
This is a read-only property that specifies the data type for the node.
Syntax: node.definition
This property returns the definition of the node in the DTD or schema.
Syntax: node.firstChild
This is a read-only property that returns the first child node of a node. If there is none, it returns null.
Syntax: node.lastChild
This is a read-only property that returns the last child node of a node. If there is none, it returns null.
Syntax: characterData.length
This property is read-only and contains the length of the data string in characters.
Syntax: object.namespaceURI
This property is read-only and returns the URI (Universal Resource Indentifier) of the namespace.
Syntax: node.nextSibling
This property returns the next node in the parent's child list, or null if there is none or the node is of a type that cannot be a child node (Attr, Document, DocumentFragment).
Syntax: node.nodeName
This property is read-only and contains the name of the node, depending on type.
Syntax: node.nodeType
This property is read-only and contains the name of the node, depending on type.
Syntax: node.nodeTypedValue
This property contains the value of this node expressed in its defined data type.
Syntax: node.nodeTypeString
This property is read-only and returns the node type in string form.
Syntax: node.nodeValue
This property contains the value of the node, depending on type.
Syntax: node.ownerDocument
This property returns the Document object to which the node belongs. If the node itself is a document, then it returns null.
Syntax: node.parentNode
This is a read-only property that returns the parent node of all nodes except Document, DocumentFragment and Attr, which cannot have parent nodes.
Syntax: node.parsed
This property returns a boolean value of true if this node and all of its descendants have been parsed and instantiated. Otherwise it returns false.
Syntax: object.prefix
Property This property is read-only and returns the namespace prefix, or an empty string if none is specified. For example, it would return 'xxx' for the element xxx:yyy.
Syntax: node.previousSibling
This property returns the previous node in the parent's child list, or null if there is none or the node is of a type that cannot be an child node (Attr, Document, DocumentFragment).
Syntax: node.specified
This property returns a boolean value which indicates whether or not this attribute has a value specified in the XML document.
Syntax: node.text
This property contains the text content of this node and its subtrees.
Syntax: node.xml
This property contains the XML representation of this node and its descendants.
Syntax: node.appendChild(tagName)
This method appends a new child node to the list of children for this node.
Syntax: characterData.appendData(data)
This method appends the specified string to existing string data.
Syntax: node.cloneNode(deep)
This method creates a clone node which is an exact replica of this node.
Syntax: characterData.deleteData(offset, count)
This method is used to remove the specified range of characters from string data.
Syntax: node.hasChildNodes
This method is a convenient way to determine whether a node has child nodes, returning true if it has, and false if not.
Syntax: node.insertBefore(newChild, refChild)
This method is used to insert a new child node before an existing one. If no child node exists, the new child node becomes the first.
Syntax: characterData.insertData(offset, data)
This method is used to insert a string at the specified offset.
Syntax: node.removeChild(oldChild)
This method removes the specified node from the list of children and returns it.
Syntax: node.replaceChild(newChild, oldChild)
This method is used to replace one of a node's children with another. It returns the old child.
Syntax: characterData.replaceData(offset, count, data)
This method replaces the characters from the specified offset with the supplied string data.
Syntax: node.selectNodes(patternString)
This method creates a NodeList of all matching descendant nodes returned by the specified pattern-matching operation.
Syntax: node.selectSingleNode(patternString)
This method returns an object for the first descendant node to match the specified pattern.
Syntax: characterData.substringData(offset, count)
This method returns a substring consisting of the specified range of characters.
Syntax: node.transformNode(stylesheet)
This method processes this node and its descendants using the specified XSL stylesheet, and returns the resulting transformation.
Syntax: node.transformNodeToObject(stylesheet, outputObject)
This method processes this node and its descendants using the specified XSL stylesheet, and returns the resulting transformation in the specified object.