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>
Code (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)
Output:
CHF Swiss Francs
length: 16
Swiss
denotes a Microsoft extension to the W3C DOM.
PROPERTIES
attributes Property
This is a read-only property that returns an
NamedNodeMap for nodes that can have
attributes.
Syntax: Node.attributes
baseName Property
This is a read-only property that returns the base name for a node.
Syntax: Node.baseName
childNodes Property
This is a read-only property containing a node list of all children for those elements that
can have them.
Syntax: Node.childNodes
data Property
This property contains the data for this node, depending on node type.
Syntax: CharacterData.data
dataType Property
This is a read-only property that specifies the data type for the node.
Syntax: Node.dataType
definition Property
This property returns the definition of the node in the DTD or schema.
Syntax: Node.definition
firstChild Property
This is a read-only property that returns the first child node of a node. If there is none,
it returns null.
Syntax: Node.firstChild
lastChild Property
This is a read-only property that returns the last child node of a node. If there is none,
it returns null.
Syntax: Node.lastChild