public class NodeCollection
extends java.lang.Object
implements java.lang.Iterable
To learn more, visit the Aspose.Words Document Object Model (DOM) documentation article.
NodeCollection does not own the nodes it contains, rather, is just a selection of nodes of the specified type, but the nodes are stored in the tree under their respective parent nodes.
NodeCollection supports indexed access, iteration and provides add and remove methods.
The NodeCollection collection is "live", i.e. changes to the children of the node object that it was created from are immediately reflected in the nodes returned by the NodeCollection properties and methods.
NodeCollection is returned by M:Aspose.Words.CompositeNode.GetChildNodes(Aspose.Words.NodeType,System.Boolean) and also serves as a base class for typed node collections such as SectionCollection, ParagraphCollection etc.
NodeCollection can be "flat" and contain only immediate children of the node it was created from, or it can be "deep" and contain all descendant children.
| Modifier and Type | Method and Description |
|---|---|
void |
add(Node node)
Adds a node to the end of the collection.
|
void |
clear()
Removes all nodes from this collection and from the document.
|
boolean |
contains(Node node)
Determines whether a node is in the collection.
|
Node |
get(int index)
Retrieves a node at the given index.
|
CompositeNode |
getContainer() |
int |
getCount()
Gets the number of nodes in the collection.
|
Node |
getCurrentNode() |
Node |
getNextMatchingNode(Node curNode) |
int |
indexOf(Node node)
Returns the zero-based index of the specified node.
|
void |
insert(int index,
Node node)
Inserts a node into the collection at the specified index.
|
java.util.Iterator |
iterator()
Provides a simple "foreach" style iteration over the collection of nodes.
|
void |
remove(Node node)
Removes the node from the collection and from the document.
|
void |
removeAt(int index)
Removes the node at the specified index from the collection and from the document.
|
Node[] |
toArray()
Copies all nodes from the collection to a new array of nodes.
|
public Node get(int index)
index - An index into the collection of nodes.Node value.public void add(Node node)
The node is inserted as a child into the node object from which the collection was created.
If the newChild is already in the tree, it is first removed.
If the node being inserted was created from another document, you should use M:Aspose.Words.DocumentBase.ImportNode(Aspose.Words.Node,System.Boolean,Aspose.Words.ImportFormatMode) to import the node to the current document. The imported node can then be inserted into the current document.
node - The node to be added to the end of the collection.com.aspose.words.net.System.NotSupportedException - The NodeCollection is a "deep" collection.public void insert(int index,
Node node)
The node is inserted as a child into the node object from which the collection was created.
If the index is equal to or greater than Count, the node is added at the end of the collection.
If the index is negative and its absolute value is greater than Count, the node is added at the end of the collection.
If the newChild is already in the tree, it is first removed.
If the node being inserted was created from another document, you should use M:Aspose.Words.DocumentBase.ImportNode(Aspose.Words.Node,System.Boolean,Aspose.Words.ImportFormatMode) to import the node to the current document. The imported node can then be inserted into the current document.
index - The zero-based index of the node. Negative indexes are allowed and indicate access from the back of the list. For example -1 means the last node, -2 means the second before last and so on.node - The node to insert.com.aspose.words.net.System.NotSupportedException - The NodeCollection is a "deep" collection.public void remove(Node node)
node - The node to remove.public void removeAt(int index)
index - The zero-based index of the node. Negative indexes are allowed and indicate access from the back of the list. For example -1 means the last node, -2 means the second before last and so on.public void clear()
public boolean contains(Node node)
This method performs a linear search; therefore, the average execution time is proportional to Count.
node - The node to locate.public int indexOf(Node node)
node - The node to locate.public Node[] toArray()
You should not be adding/removing nodes while iterating over a collection of nodes because it invalidates the iterator and requires refreshes for live collections.
To be able to add/remove nodes during iteration, use this method to copy nodes into a fixed-size array and then iterate over the array.
public java.util.Iterator iterator()
iterator in interface java.lang.Iterablepublic Node getNextMatchingNode(Node curNode) throws java.lang.Exception
java.lang.Exceptionpublic int getCount()
public Node getCurrentNode()
public CompositeNode getContainer()