An IXMLDOMText object represents the text content of an element. It is commonly referred to as a text node.
Use the createTextNode method from the DOMDocument object to create a new text node. You must supply the text node’s data.
{Create a text node containing a seller’s first name.} textNode = xmlDoc.createTextNode("Adam");
Creating a new text node with the createTextNode method does not add the text node to an XML document. You must add the text node to an element with the appendChild method, the insertChild method, or the replaceChild method.
Use the insertBefore method to insert a text node before an element or another text node. You must specify the text node that you are adding as well as the element or text node that you are adding it before.
{Add the text node before the element.} element.insertBefore(textNode, element);
You can also use the appendChild method to add a text node after all elements and text nodes.
{Add the text node to the element.} element.appendChild(textNode);
A text node can be added to an IXMLDOMElement object. |
The childNodes collection contains all of the nodes in an XML document. You retrieve a node from the childNodes collection with the item method by the index associated with the object. To find a text node in the childNodes collection, retrieve each object as an IXMLDOMNode object. Then test the object’s node type with the nodeType property.
{Retrieve the first node in the childNodes collection and ascertain if it is an IXMLDOMText object.} node = element.childNodes.item[0]; if(node.nodeType = NODE_TEXT) then textNode = node; end if;
Use the replaceChild method to replace a text node or an element in an element with a text node. The element or text node that you are replacing is returned.
{Replace the element with a text node.} element = xmlDoc.replaceChild(textNode, element);
Use the the length property to retrieve the length of the data in a text node.
{Retrieve the length of the text node’s data.} dataLength = textNode.length;
Use the data property to retrieve the data stored in a text node.
{Retrieve the data stored in the text node.} nodeData = textNode.data;
You can also use the data property to set the data stored in a text node.
{Set the data stored in the text node to "Adam Barr".} textNode.data = "Adam Barr";
When you set the data stored in a text node with the data property, you replace the data previously stored in the text node. |
Use the appendData method to add data to the data currently stored in a text node.
{Add the string " Barr" to the data stored in the text node.} textNode.appendData(" Barr");
You can also use the insertData method to add data to a text node at a specified position.
{Add the string "Robert " to the text node at the fifth position.} textNode.insertData(5, "Robert ");
Use the deleteData method to delete a string of data from a text node at a specified position. You must specify the length of the string to remove.
{Remove seven characters from the string, beginning at the fifth position.} textNode.deleteData(5, 7);
Use the removeChild method to remove a text node from an element.
{Remove the text node from the element.} element.removeChild(textNode);