User Guide : Scripting : Script Objects : DOMNode Object Type
 
Share this page             
DOMNode Object Type
Conceptually, DOM stores a document as a tree of nodes. All elements, attributes, chunks of text, etc. are simply different types of nodes. Externally, the DataConnect Runtime Engine does not differentiate between different types of nodes (in other words, we only support the one DOMNode data type). However, internally each node has a specific type, and capabilities dependent on the type. We provide some methods and properties to manipulate the various nodes.
Properties
 
Property
Type
Access
Description
Attribute Property
String
RW
Get/set node attribute value for an element node.
AttributeCount Property
Integer
RO
Get attribute count for an element node.
AttributeNode Property
DOMNode
RO
Get the nth attribute for the element node.
FirstChild Property
DOMNode
RO
Get the first child element of the node.
LastChild Property
DOMNode
RO
Get the last child element of the node.
Name Property
String
RO
Get the node name.
NextSibling Property
DOMNode
RO
Get the next sibling of the node.
Parent Property
DOMNode
RO
Get the parent node for the node.
PrevSibling Property
DOMNode
RO
Get the previous sibling of the node.
Type Property
Integer
RO
Get the node type.
Value Property
String
RW
Get/set the value of a node (default property).
Attribute Property
Use the Attribute property to get or set an attribute value for an element node. This read/write property may only be applied to an element type of node. It gets or sets the value of the named attribute. If an attribute by that name does not exist, null is returned when reading. When writing, if the named attribute does not exist it is created, otherwise its value is set as specified.
Syntax
node.Attribute(name)
Parameters
 
Type
Required
Description
DOMNode
Yes
Reference to the DOMNode that is the subject of the property or method invocation.
String
Yes
Attribute name.
Exceptions
The Attribute property may return the following exceptions if there is an error at run time.
Exception
Description
ERR_TYPEMISMATCH
Returned if used with a node other than an element node.
Example
'The following example shows how to set the value for an attribute named
testattr.
node.attribute("testattr") = "test value"
AttributeCount Property
This read-only property returns the number of attributes contained in the element.
Syntax
node.AttributeCount
Parameters
 
Type
Required
Description
DOMNode
Yes
Reference to the DOMNode that is the subject of the property or method invocation.
Exceptions
The AttributeCount property may return the following exceptions if there is an error at run time.
Exception
Description
ERR_TYPEMISMATCH
Returned if used with a node other than an element node.
Example
'The following example shows how to reference attribute count.

element.AttributeCount
AttributeNode Property
This read-only property returns the attribute node at the given position in the element. It would be used in conjunction with AttributeCount to determine the number of attributes contained. If the index is out of range an ERR_ARRAYBOUNDS error is returned. Note that the index is 0-based.
Syntax
node.AttributeNode(attrno)
Parameters
 
Type
Required
Description
DOMNode
Yes
Reference to the DOMNode that is the subject of the property or method invocation.
Integer
Yes
Attribute index.
Exceptions
The AttributeNode property may return the following exceptions if there is an error at run time.
Exception
Description
ERR_ARRAYBOUNDS
Returned if the index is out of range.
ERR_TYPEMISMATCH
Returned if used with a node other than an element node.
Example
'The following example shows how to reference attribute nodes:
Dim attr as DOMNode
For ano = 1 to element.AttributeCount
  Set attr = element.AttributeNode(ano - 1)
  ' do something with the attribute node...
Next ano
FirstChild Property
Get the first child of a DOMNode object. This read-only property returns the first child of this node. Nothing is returned if the node does not have a child.
Syntax
node.FirstChild
Parameters
 
Type
Required
Description
DOMNode
Yes
Reference to the DOMNode that is the subject of the property or method invocation.
Example
'The following example shows how to reference the first child.
Dim child As DOMNode
Set child = node.FirstChild
LastChild Property
Get the last child of a DOMNode object. This read-only property returns the last child of this node. Nothing is returned if the node does not have a child.
Syntax
node.LastChild
Parameters
 
Type
Required
Description
DOMNode
Yes
Reference to the DOMNode that is the subject of the property or method invocation.
Example
'The following example shows how to reference the last child.
Dim child As DOMNode
Set child = node.LastChild
Name Property
Get the name of a DOMNode object. This read-only property returns the name of the node. For element and attribute nodes, it returns the actual name of the element or attribute. For other node types, it returns mostly useless information (i.e. "#text" for a text node).
Syntax
node.Name
Parameters
 
Type
Required
Description
DOMNode
Yes
Reference to the DOMNode that is the subject of the property or method invocation.
Example
'Print the name of a DOMNode object called node.
Print("Node name: " & node.Name)
NextSibling Property
Get the next sibling for a DOMNode object. This read-only property returns the next sibling of this node. Nothing is returned if the node does not have a next sibling.
Syntax
node.NextSibling
Parameters
 
Type
Required
Description
DOMNode
Yes
Reference to the DOMNode that is the subject of the property or method invocation.
Example
'The following example shows how to check for a next sibling:
Dim nextNode As DOMNode
Set nextNode = node.NextSibling
If nextNode Is Nothing Then
  LogMessage("Info","No next sibling found for " & node.Name)
End If
Parent Property
Get the parent node for a DOMNode object. This read-only property returns the parent node of the given node, or Nothing if the node does not have a parent (has not been inserted in the tree).
Syntax
node.Parent
Parameters
 
Type
Required
Description
DOMNode
Yes
Reference to the DOMNode that is the subject of the property or method invocation.
Example
'The following example shows how to check to see if a node has a parent:
Dim parent As DOMNode
Set parent = node.Parent
If parent Is Nothing Then
  LogMessage("Info","No parent found for " & node.Name)
End If
PrevSibling Property
Get the previous sibling for a DOMNode object. This read-only property returns the previous sibling of this node. Nothing is returned if the node does not have a previous sibling.
Syntax
node.PrevSibling
Parameters
 
Type
Required
Description
DOMNode
Yes
Reference to the DOMNode that is the subject of the property or method invocation.
Example
'The following example shows how to check for a previous sibling:
Dim prev As DOMNode
Set prev = node.PrevSibling
If prev Is Nothing Then
  LogMessage("Info","No previous sibling found for " & node.Name)
End If
Type Property
Get the DOMNode type. This read-only property returns the type of the specific node. The particular values, and their representational names are in this table.
Node_Type
Value
Description
DOM_ELEMENT_NODE
1
Element node
DOM_ATTRIBUTE_NODE
2
Attribute node
DOM_TEXT_NODE
3
PCDATA node
DOM_CDATA_SECTION_NODE
4
CDATA section node
DOM_ENTITY_REFERENCE_NODE
5
Entity reference node
DOM_ENTITY_NODE
6
Entity node
DOM_PROCESSING_INSTRUCTION_NODE
7
XML processing instruction node
DOM_COMMENT_NODE
8
Comment node
DOM_DOCUMENT_NODE
9
Document node
DOM_DOCUMENT_TYPE_NODE
10
Document type node
DOM_DOCUMENT_FRAGMENT_NODE
11
Document fragment node
DOM_NOTATION_NODE
12
Notation node
DOM_XML_DECL_NODE
13
XML declaration node
Syntax
node.Type
Parameters
 
Type
Required
Description
DOMNode
Yes
Reference to the DOMNode that is the subject of the property or method invocation.
Example
'The following example shows how to check the type of a node:
If node.Type = DOM_XML_DECL_NODE Then
  LogMessage("Info", "Found an XMLDecl node")
End If
Value Property
Get or set the value for a DOMNode object. This read/write property gets or sets the value of a node. If an attempt is made to set the value of a node type other than attribute, text or CDATA an ERR_TYPEMISMATCH exception is returned.
Syntax
node.Value
'OR
node.Value = value
Parameters
 
Type
Required
Description
DOMNode
Yes
Reference to the DOMNode that is the subject of the property or method invocation.
String
Yes (when assigning a value)
String expression used to assign the value to the node.
Exceptions
The Value property may return the following exceptions if there is an error at run time:
Exception
Description
ERR_TYPEMISMATCH
Returned if the method is unable to create the new element.
Example
'The following example shows how to assign a string value to a node:
node.Value = "This is a value"
Methods
 
Method
Type
Description
AppendChild Method
NA -
Append a child node to the node.
Print Method
String
Print the DOM object to an XML string.
AppendChild Method
Append a child DOMNode object to another DOMNode object. This method appends the given node as the last child of this node. This is how the DOM tree is actually built.
Syntax
node.AppendChild(child)
Parameters
 
Type
Required
Description
DOMNode
Yes
Reference to the DOMNode object that is the subject of the property or method invocation.
DOMNode
Yes
Reference to the child DOMNode to append.
Exceptions
The AppendChild method may return the following exceptions if there is an error at run time.
Exception
Description
ERR_TYPEMISMATCH
Returned if the argument is not a DOMNode.
Examples
The follow example shows how to append a new text node to the root node of a document.
Dim node as DOMNode
Dim child as DOMNode
Set node = doc.DocumentElement
Set child = doc.CreateTextNode("Some text")
Node.AppendChild(child)
Linking Nodes
In this example, two nodes are created, an Element node, and a Text node. To link the two nodes, the Text node is declared a child of the element node using the AppendChild method.
<root>
  <firstchild> </firstchild>
</root>
To create the first node, use the CreateElement method of the DOMDocument object. This creates tags of the XML document. To create the text node, use the CreateTextNode method of the DOMDocument object. The final step ties the two nodes together. Use the AppendChild method to the make the Text node a child of the Element node. See the example below.
Dim DOM as DOMDocument 'sets the document object model
Dim 1 as DOMNode 'sets 1 as a document node
Dim 2 as DOMNode 'sets 2 as a document node
Dim root as DOMNode 'sets "root" as a document node
Set root = DOM.DocumentElement 'defines "root" as an element type
Set 1 = root.firstchild 'defines "root" as the parent of "firstchild"
Set 2 = 1.firstchild 'defines node 2 as a child of root
root.AppendChild(1) 'appends firstchild as a child element of root; creates tags
Print Method
Use the Print method to print a DOMNode object to a string.
Syntax
node.Print([encoding][, xmldecl][, prettyprint])
Parameters
 
Type
Required
Description
DOMNode
Yes
Reference to the DOMNode object that is the subject of the property or method invocation.
Integer
No
Character set to use for encoding the printed document (one of the ENC_xxx constants). If not supplied, the default is UTF-8.
Boolean
No
Flag indicates whether or not to include an xmldecl line. The default is false. Do not include an xmldecl line.
Boolean
No
Flag indicating whether or not to use pretty-printing. If set to true, an attempt is made to insert indentation and newlines to make the result easier to read. The default is false.
Exceptions
The Print method may return the following exceptions if there is an error at run time:
Exception
Description
ERR_DOMERROR
Returned if the method is unable to print the document.
Example
'The follow code snippet prints the root DOMNode for the DOMDocument doc using the default Print parameters.
Dim rootnode as DOMNode
Set rootnode = doc.DocumentElement
Dim pxml
pxml = rootnode.Print()
Operators
 
Operator
Type
Description
New
DOMNode
Create a new object.