| Nodes |  |  |
Nodes Collection
See also: Using collections.
| |

 |
Add method, ( NodeOrType, [Before] ) As Object.
Adds a new node to the specified Nodes collection. Returns a Node object that represents the node to be added.
NodeOrType A String, that represents the typename of a new node, or a Proto object, that represents a template for a new node, or a Node object, that represents the definition for a new node (by means of the DEF/USE syntax).
Before (Optional) An index of a new item in the collection. The node to be added is inserted in the collection before the node identified by the Before argument.
If a numeric expression, Before must be a number from 1 to Count.
If a string expression, Before is a node name that can be used instead of the positional index.
If an object expression, Before is a Node object from the collection, or any Entity object with the same owner, or a Range object. In the last case, a new node will be inserted before the end of the text range.
By default, a new node is inserted at the end of the collection.
The following example creates a Group node and adds a reference to it as a child.
Dim n As Node
Set n = Document.RootNodes.Add("Group")
n("children").Add n
|
See also: Add property of the MFValue object.
|

| |

 |
Count property, read-only, Long.
Returns the number of items in the specified collection.
|

| |

 |
Item property, default, read-only, ( IndexOrName ) As Object.
Returns a Node object that represents a member of the collection, either by position or by name.
IndexOrName The name or index number of a member of the collection. The index can be a numeric expression (a number from 1 to the value of the collection's Count property), a constant, or a string, that represents the name of an existing node (by means of the DEF/USE syntax) from the collection. If the value provided as IndexOrName doesn't match any existing member of the collection, an error occurs.
The Item property is a default property for a collection and collections are a default property for most objects, that would reduce code in Visual Basic and VBScript macros. The following example sets the value to the geometry field of the SomeShape node.
Document.Nodes("SomeShape").Fields("geometry").Value = "Box"
'Reduced code:
Document("SomeShape")("geometry") = "Box"
'More reduced code (only in Visual Basic):
Document!SomeShape!geometry = "Box"
|
|

| |

 |
_NewEnum property, read-only.
References nodes in the specified collection.
With C++, you can browse a collection to find a particular item by using the _NewEnum or the Item properties. In Visual Basic and VBScript, you do not need to use the _NewEnum property, because it is automatically used in the implementation of For Each ... Next or in For ... in statement in JavaScript.
The following example in Visual Basic prints all node names (in the global context) to the Immediate pane.
Dim n As Node
For Each n In Document.Nodes
Debug.Print n.Name
Next n
|
The following example is a C++ code snippet you can insert into an add-in's command handler method. This example uses the _NewEnum property to iterate through all named nodes in the document and traces all node names.
Nodes *pNodes;
pDoc->get_Nodes( &pNodes );
IEnumVARIANT *pNodesEnum;
pNodes->get__NewEnum( (IUnknown**) &pNodesEnum );
VARIANT varNode;
VariantInit( &varNode );
while( pNodesEnum->Next( 1, &varNode, NULL ) == S_OK )
{
Node *pNode;
if ( SUCCEEDED(varNode.pdispVal->
QueryInterface( IID_Node, (void**) &pNode)))
{
BSTR bstrName
pNode->get_Name( &bstrName );
TRACE( "%ws\n", bstrName );
SysFreeString( bstrName );
pNode->Release();
}
VariantClear( &varNode );
}
pNodesEnum->Release();
pNodes->Release();
|
|

|
|
|