Base class for nodes that can contain other nodes.
A document is represented as a tree of nodes, similar to DOM or XmlDocument.
For more info see the Composite design pattern.
The CompositeNode class:
Shows how to traverse through a composite node's collection of child nodes.
#include <Aspose.Words.Cpp/CompositeNode.h>
Public Member Functions | |
SharedPtr< Node > | AppendChild (const SharedPtr< Node > &newChild) |
Adds the specified node to the end of the list of child nodes for this node. More... | |
SharedPtr< NodeCollection > | get_ChildNodes () |
Gets all immediate child nodes of this node. More... | |
int32_t | get_Count () |
Gets the number of immediate children of this node. More... | |
SharedPtr< Node > | get_FirstChild () const |
Gets the first child of the node. More... | |
bool | get_HasChildNodes () |
Returns true if this node has any child nodes. More... | |
bool | get_IsComposite () override |
Returns true as this node can have child nodes. More... | |
SharedPtr< Node > | get_LastChild () const |
Gets the last child of the node. More... | |
SharedPtr< Node > | GetChild (NodeType nodeType, int32_t index, bool isDeep) |
Returns an Nth child node that matches the specified type. More... | |
SharedPtr< NodeCollection > | GetChildNodes (NodeType nodeType, bool isDeep) |
Returns a live collection of child nodes that match the specified type. More... | |
SharedPtr< IEnumerator< SharedPtr< Node > > > | GetEnumerator () override |
Provides support for the for each style iteration over the child nodes of this node. More... | |
String | GetText () override |
Gets the text of this node and of all its children. More... | |
virtual const TypeInfo & | GetType () const override |
int32_t | IndexOf (const SharedPtr< Node > &child) |
Returns the index of the specified child node in the child node array. More... | |
SharedPtr< Node > | InsertAfter (const SharedPtr< Node > &newChild, const SharedPtr< Node > &refChild) |
Inserts the specified node immediately after the specified reference node. More... | |
SharedPtr< Node > | InsertBefore (const SharedPtr< Node > &newChild, const SharedPtr< Node > &refChild) |
Inserts the specified node immediately before the specified reference node. More... | |
virtual bool | Is (const TypeInfo &target) const override |
SharedPtr< Node > | PrependChild (const SharedPtr< Node > &newChild) |
Adds the specified node to the beginning of the list of child nodes for this node. More... | |
void | RemoveAllChildren () |
Removes all the child nodes of the current node. More... | |
SharedPtr< Node > | RemoveChild (const SharedPtr< Node > &oldChild) |
Removes the specified child node. More... | |
void | RemoveSmartTags () |
Removes all SmartTag descendant nodes of the current node. More... | |
SharedPtr< NodeList > | SelectNodes (const String &xpath) |
Selects a list of nodes matching the XPath expression. More... | |
SharedPtr< Node > | SelectSingleNode (const String &xpath) |
Selects the first Node that matches the XPath expression. More... | |
void | SetTemplateWeakPtr (uint32_t argument) override |
![]() | |
virtual bool | Accept (SharedPtr< DocumentVisitor > visitor)=0 |
Accepts a visitor. More... | |
SharedPtr< Node > | Clone (bool isCloneChildren) |
Creates a duplicate of the node. More... | |
int32_t | get_CustomNodeId () const |
Specifies custom node identifier. More... | |
virtual SharedPtr< DocumentBase > | get_Document () const |
Gets the document to which this node belongs. More... | |
virtual bool | get_IsComposite () |
Returns true if this node can contain other nodes. More... | |
SharedPtr< Node > | get_NextSibling () |
Gets the node immediately following this node. More... | |
virtual NodeType | get_NodeType () const =0 |
Gets the type of this node. More... | |
SharedPtr< CompositeNode > | get_ParentNode () |
Gets the immediate parent of this node. More... | |
SharedPtr< Node > | get_PreviousSibling () |
Gets the node immediately preceding this node. More... | |
SharedPtr< Range > | get_Range () |
Returns a Range object that represents the portion of a document that is contained in this node. More... | |
SharedPtr< CompositeNode > | GetAncestor (NodeType ancestorType) |
Gets the first ancestor of the specified NodeType. More... | |
template<typename T > | |
T | GetAncestorOf () |
virtual String | GetText () |
Gets the text of this node and of all its children. More... | |
virtual const TypeInfo & | GetType () const override |
virtual bool | Is (const TypeInfo &target) const override |
SharedPtr< Node > | NextPreOrder (const SharedPtr< Node > &rootNode) |
Gets next node according to the pre-order tree traversal algorithm. More... | |
SharedPtr< Node > | PreviousPreOrder (const SharedPtr< Node > &rootNode) |
Gets the previous node according to the pre-order tree traversal algorithm. More... | |
void | Remove () |
Removes itself from the parent. More... | |
void | set_CustomNodeId (int32_t value) |
Setter for get_CustomNodeId. More... | |
String | ToString (SaveFormat saveFormat) |
Exports the content of the node into a string in the specified format. More... | |
String | ToString (const SharedPtr< SaveOptions > &saveOptions) |
Exports the content of the node into a string using the specified save options. More... | |
Static Public Member Functions | |
static const TypeInfo & | Type () |
![]() | |
static String | NodeTypeToString (NodeType nodeType) |
A utility method that converts a node type enum value into a user friendly string. More... | |
static const TypeInfo & | Type () |
System::SharedPtr< Aspose::Words::Node > Aspose::Words::CompositeNode::AppendChild | ( | const System::SharedPtr< Aspose::Words::Node > & | newChild | ) |
Adds the specified node to the end of the list of child nodes for this node.
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.
newChild | The node to add. |
Shows how to construct an Aspose.Words document by hand.
System::SharedPtr< Aspose::Words::NodeCollection > Aspose::Words::CompositeNode::get_ChildNodes | ( | ) |
Gets all immediate child nodes of this node.
Note, ChildNodes is equivalent to calling GetChildNodes(NodeType.Any, false)
and creates and returns a new collection every time it is accessed.
If there are no child nodes, this property returns an empty collection.
Shows how to traverse through a composite node's collection of child nodes.
int32_t Aspose::Words::CompositeNode::get_Count | ( | ) |
Gets the number of immediate children of this node.
Shows how to add, update and delete child nodes in a CompositeNode's collection of children.
System::SharedPtr< Aspose::Words::Node > Aspose::Words::CompositeNode::get_FirstChild | ( | ) | const |
Gets the first child of the node.
Shows how to traverse a composite node's tree of child nodes.
Shows how to use a node's NextSibling property to enumerate through its immediate children.
bool Aspose::Words::CompositeNode::get_HasChildNodes | ( | ) |
Returns true if this node has any child nodes.
Shows how to combine the rows from two tables into one.
|
overridevirtual |
Returns true as this node can have child nodes.
Shows how to traverse a composite node's tree of child nodes.
Reimplemented from Aspose::Words::Node.
System::SharedPtr< Aspose::Words::Node > Aspose::Words::CompositeNode::get_LastChild | ( | ) | const |
Gets the last child of the node.
Shows how to use of methods of Node and CompositeNode to remove a section before the last section in the document.
System::SharedPtr< Aspose::Words::Node > Aspose::Words::CompositeNode::GetChild | ( | Aspose::Words::NodeType | nodeType, |
int32_t | index, | ||
bool | isDeep | ||
) |
Returns an Nth child node that matches the specified type.
If index is out of range, a null is returned.
nodeType | Specifies the type of the child node. |
index | Zero based index of the child node to select. Negative indexes are also allowed and indicate access from the end, that is -1 means the last node. |
isDeep | True to select from all child nodes recursively. False to select only among immediate children. See remarks for more info. |
Shows how to apply the properties of a table's style directly to the table's elements.
Shows how to traverse through a composite node's collection of child nodes.
System::SharedPtr< Aspose::Words::NodeCollection > Aspose::Words::CompositeNode::GetChildNodes | ( | Aspose::Words::NodeType | nodeType, |
bool | isDeep | ||
) |
Returns a live collection of child nodes that match the specified type.
The collection of nodes returned by this method is always live.
A live collection is always in sync with the document. For example, if you selected all sections in a document and enumerate through the collection deleting the sections, the section is removed from the collection immediately when it is removed from the document.
nodeType | Specifies the type of nodes to select. |
isDeep | True to select from all child nodes recursively. False to select only among immediate children. |
Shows how to print all of a document's comments and their replies.
Shows how to extract images from a document, and save them to the local file system as individual files.
Shows how to add, update and delete child nodes in a CompositeNode's collection of children.
|
override |
Provides support for the for each style iteration over the child nodes of this node.
Shows how to traverse through a composite node's collection of child nodes.
|
overridevirtual |
Gets the text of this node and of all its children.
The returned string includes all control and special characters as described in ControlChar.
Shows the difference between calling the GetText and ToString methods on a node.
Shows how to output all paragraphs in a document that are list items.
Reimplemented from Aspose::Words::Node.
Reimplemented in Aspose::Words::Paragraph, and Aspose::Words::Tables::Row.
|
overridevirtual |
Reimplemented from Aspose::Words::Node.
Reimplemented in Aspose::Words::Body, Aspose::Words::BuildingBlocks::BuildingBlock, Aspose::Words::BuildingBlocks::GlossaryDocument, Aspose::Words::Comment, Aspose::Words::Document, Aspose::Words::DocumentBase, Aspose::Words::Drawing::GroupShape, Aspose::Words::Drawing::Shape, Aspose::Words::Drawing::ShapeBase, Aspose::Words::HeaderFooter, Aspose::Words::InlineStory, Aspose::Words::Markup::SmartTag, Aspose::Words::Markup::StructuredDocumentTag, Aspose::Words::Math::OfficeMath, Aspose::Words::Notes::Footnote, Aspose::Words::Paragraph, Aspose::Words::Section, Aspose::Words::Story, Aspose::Words::Tables::Cell, Aspose::Words::Tables::Row, and Aspose::Words::Tables::Table.
int32_t Aspose::Words::CompositeNode::IndexOf | ( | const System::SharedPtr< Aspose::Words::Node > & | child | ) |
Returns the index of the specified child node in the child node array.
Shows how to get the index of a given child node from its parent.
System::SharedPtr< Aspose::Words::Node > Aspose::Words::CompositeNode::InsertAfter | ( | const System::SharedPtr< Aspose::Words::Node > & | newChild, |
const System::SharedPtr< Aspose::Words::Node > & | refChild | ||
) |
Inserts the specified node immediately after the specified reference node.
If refChild is null, inserts newChild at the beginning of the list of child nodes.
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.
newChild | The Node to insert. |
refChild | The Node that is the reference node. The newNode is placed after the refNode. |
Shows how to add, update and delete child nodes in a CompositeNode's collection of children.
Shows how to replace all textbox shapes with image shapes.
System::SharedPtr< Aspose::Words::Node > Aspose::Words::CompositeNode::InsertBefore | ( | const System::SharedPtr< Aspose::Words::Node > & | newChild, |
const System::SharedPtr< Aspose::Words::Node > & | refChild | ||
) |
Inserts the specified node immediately before the specified reference node.
If refChild is null, inserts newChild at the end of the list of child nodes.
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.
newChild | The Node to insert. |
refChild | The Node that is the reference node. The newChild is placed before this node. |
Shows how to add, update and delete child nodes in a CompositeNode's collection of children.
|
overridevirtual |
Reimplemented from Aspose::Words::Node.
Reimplemented in Aspose::Words::Body, Aspose::Words::BuildingBlocks::BuildingBlock, Aspose::Words::BuildingBlocks::GlossaryDocument, Aspose::Words::Comment, Aspose::Words::Document, Aspose::Words::DocumentBase, Aspose::Words::Drawing::GroupShape, Aspose::Words::Drawing::Shape, Aspose::Words::Drawing::ShapeBase, Aspose::Words::HeaderFooter, Aspose::Words::InlineStory, Aspose::Words::Markup::SmartTag, Aspose::Words::Markup::StructuredDocumentTag, Aspose::Words::Math::OfficeMath, Aspose::Words::Notes::Footnote, Aspose::Words::Paragraph, Aspose::Words::Section, Aspose::Words::Story, Aspose::Words::Tables::Cell, Aspose::Words::Tables::Row, and Aspose::Words::Tables::Table.
System::SharedPtr< Aspose::Words::Node > Aspose::Words::CompositeNode::PrependChild | ( | const System::SharedPtr< Aspose::Words::Node > & | newChild | ) |
Adds the specified node to the beginning of the list of child nodes for this node.
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.
newChild | The node to add. |
Shows how to add, update and delete child nodes in a CompositeNode's collection of children.
void Aspose::Words::CompositeNode::RemoveAllChildren | ( | ) |
Removes all the child nodes of the current node.
Shows how to construct an Aspose.Words document by hand.
System::SharedPtr< Aspose::Words::Node > Aspose::Words::CompositeNode::RemoveChild | ( | const System::SharedPtr< Aspose::Words::Node > & | oldChild | ) |
Removes the specified child node.
The parent of oldChild is set to null after the node is removed.
oldChild | The node to remove. |
Shows how to use of methods of Node and CompositeNode to remove a section before the last section in the document.
void Aspose::Words::CompositeNode::RemoveSmartTags | ( | ) |
Removes all SmartTag descendant nodes of the current node.
Removes all smart tags from descendant nodes of a composite node.
Shows how to create smart tags.
System::SharedPtr< Aspose::Words::NodeList > Aspose::Words::CompositeNode::SelectNodes | ( | const System::String & | xpath | ) |
Selects a list of nodes matching the XPath expression.
Only expressions with element names are supported at the moment. Expressions that use attribute names are not supported.
xpath | The XPath expression. |
System::SharedPtr< Aspose::Words::Node > Aspose::Words::CompositeNode::SelectSingleNode | ( | const System::String & | xpath | ) |
Selects the first Node that matches the XPath expression.
Only expressions with element names are supported at the moment. Expressions that use attribute names are not supported.
xpath | The XPath expression. |
|
overridevirtual |
Reimplemented from System::Object.
|
static |