Represents a collection of nodes of a specific type.
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 GetChildNodes() 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.
Shows how to replace all textbox shapes with image shapes.
#include <Aspose.Words.Cpp/NodeCollection.h>
Public Member Functions | |
void | Add (const SharedPtr< Node > &node) |
Adds a node to the end of the collection. More... | |
void | Clear () |
Removes all nodes from this collection and from the document. More... | |
bool | Contains (const SharedPtr< Node > &node) |
Determines whether a node is in the collection. More... | |
int32_t | get_Count () |
Gets the number of nodes in the collection. More... | |
SharedPtr< IEnumerator< SharedPtr< Node > > > | GetEnumerator () override |
Provides a simple "foreach" style iteration over the collection of nodes. More... | |
virtual const TypeInfo & | GetType () const override |
SharedPtr< Node > | idx_get (int32_t index) |
Retrieves a node at the given index. More... | |
int32_t | IndexOf (const SharedPtr< Node > &node) |
Returns the zero-based index of the specified node. More... | |
void | Insert (int32_t index, const SharedPtr< Node > &node) |
Inserts a node into the collection at the specified index. More... | |
virtual bool | Is (const TypeInfo &target) const override |
void | Remove (const SharedPtr< Node > &node) |
Removes the node from the collection and from the document. More... | |
void | RemoveAt (int32_t index) |
Removes the node at the specified index from the collection and from the document. More... | |
ArrayPtr< SharedPtr< Node > > | ToArray () |
Copies all nodes from the collection to a new array of nodes. More... | |
Static Public Member Functions | |
static const TypeInfo & | Type () |
void Aspose::Words::NodeCollection::Add | ( | const System::SharedPtr< Aspose::Words::Node > & | node | ) |
Adds a node to the end of the collection.
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 ImportNode() 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. |
System::NotSupportedException | The NodeCollection is a "deep" collection. |
Shows how to prepare a new section node for editing.
void Aspose::Words::NodeCollection::Clear | ( | ) |
Removes all nodes from this collection and from the document.
Shows how to remove all sections from a document.
bool Aspose::Words::NodeCollection::Contains | ( | const System::SharedPtr< Aspose::Words::Node > & | node | ) |
Determines whether a node is in the collection.
This method performs a linear search; therefore, the average execution time is proportional to Count.
node | The node to locate. |
Shows how to work with a NodeCollection.
int32_t Aspose::Words::NodeCollection::get_Count | ( | ) |
Gets the number of nodes in the collection.
Shows how to traverse through a composite node's collection of child nodes.
Shows how to find out if a tables are nested.
|
override |
Provides a simple "foreach" style iteration over the collection of nodes.
|
overridevirtual |
Reimplemented from System::Object.
Reimplemented in Aspose::Words::BuildingBlocks::BuildingBlockCollection, Aspose::Words::CommentCollection, Aspose::Words::HeaderFooterCollection, Aspose::Words::ParagraphCollection, Aspose::Words::RunCollection, Aspose::Words::SectionCollection, Aspose::Words::Tables::CellCollection, Aspose::Words::Tables::RowCollection, and Aspose::Words::Tables::TableCollection.
System::SharedPtr< Aspose::Words::Node > Aspose::Words::NodeCollection::idx_get | ( | int32_t | index | ) |
Retrieves a node at the given index.
The index is zero-based.
Negative indexes are allowed and indicate access from the back of the collection. For example -1 means the last item, -2 means the second before last and so on.
If index is greater than or equal to the number of items in the list, this returns a null reference.
If index is negative and its absolute value is greater than the number of items in the list, this returns a null reference.
index | An index into the collection of nodes. |
Shows how to traverse through a composite node's collection of child nodes.
int32_t Aspose::Words::NodeCollection::IndexOf | ( | const System::SharedPtr< Aspose::Words::Node > & | node | ) |
Returns the zero-based index of the specified node.
This method performs a linear search; therefore, the average execution time is proportional to Count.
node | The node to locate. |
Shows how to get the index of a node in a collection.
void Aspose::Words::NodeCollection::Insert | ( | int32_t | index, |
const System::SharedPtr< Aspose::Words::Node > & | node | ||
) |
Inserts a node into the collection at the specified index.
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 ImportNode() 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. |
System::NotSupportedException | The NodeCollection is a "deep" collection. |
Shows how to work with a NodeCollection.
|
overridevirtual |
Reimplemented from System::Object.
Reimplemented in Aspose::Words::BuildingBlocks::BuildingBlockCollection, Aspose::Words::CommentCollection, Aspose::Words::HeaderFooterCollection, Aspose::Words::ParagraphCollection, Aspose::Words::RunCollection, Aspose::Words::SectionCollection, Aspose::Words::Tables::CellCollection, Aspose::Words::Tables::RowCollection, and Aspose::Words::Tables::TableCollection.
void Aspose::Words::NodeCollection::Remove | ( | const System::SharedPtr< Aspose::Words::Node > & | node | ) |
Removes the node from the collection and from the document.
node | The node to remove. |
Shows how to work with a NodeCollection.
void Aspose::Words::NodeCollection::RemoveAt | ( | int32_t | index | ) |
Removes the node at the specified index from the collection and from the 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. |
Shows how to add and remove sections in a document.
System::ArrayPtr< System::SharedPtr< Aspose::Words::Node > > Aspose::Words::NodeCollection::ToArray | ( | ) |
Copies all nodes from the collection to a new array of nodes.
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.
Shows how to replace all textbox shapes with image shapes.
|
static |