Aspose::Words::CompositeNode Class Referenceabstract

Detailed Description

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:

  • Provides access to the child nodes.
  • Implements Composite operations such as insert and remove children.
  • Provides methods for XPath navigation.

#include <Aspose.Words.Cpp/Model/Nodes/CompositeNode.h>

+ Inheritance diagram for Aspose::Words::CompositeNode:

Public Member Functions

SharedPtr< NodeAppendChild (SharedPtr< Node > newChild)
 Adds the specified node to the end of the list of child nodes for this node. More...
 
SharedPtr< NodeCollectionget_ChildNodes ()
 Gets all immediate child nodes of this node. More...
 
SharedPtr< CompositeNodeget_Container ()
 
int32_t get_Count ()
 Gets the number of immediate children of this node. More...
 
SharedPtr< Nodeget_FirstChild () const
 Gets the first child of the node. More...
 
bool get_HasChildNodes ()
 Returns true if this node has any child nodes. More...
 
virtual bool get_IsComposite ()
 Returns true as this node can have child nodes. More...
 
SharedPtr< Nodeget_LastChild () const
 Gets the last child of the node. More...
 
SharedPtr< NodeGetChild (NodeType nodeType, int32_t index, bool isDeep)
 Returns an Nth child node that matches the specified type. More...
 
SharedPtr< NodeCollectionGetChildNodes (NodeType nodeType, bool isDeep)
 Returns a live collection of child nodes that match the specified type. More...
 
SharedPtr< NodeGetCurrentNode ()
 
SharedPtr< IEnumerator< SharedPtr< Node > > > GetEnumerator ()
 Provides support for the for each style iteration over the child nodes of this node. More...
 
SharedPtr< NodeGetNextMatchingNode (SharedPtr< Node > curNode)
 
virtual String GetText ()
 Gets the text of this node and of all its children. More...
 
int32_t IndexOf (SharedPtr< Node > child)
 Returns the index of the specified child node in the child node array. More...
 
SharedPtr< NodeInsertAfter (SharedPtr< Node > newChild, SharedPtr< Node > refChild)
 Inserts the specified node immediately after the specified reference node. More...
 
SharedPtr< NodeInsertBefore (SharedPtr< Node > newChild, SharedPtr< Node > refChild)
 Inserts the specified node immediately before the specified reference node. More...
 
SharedPtr< NodePrependChild (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< NodeRemoveChild (SharedPtr< Node > oldChild)
 Removes the specified child node. More...
 
void RemoveSmartTags ()
 Removes all SmartTag descendant nodes of the current node. More...
 
SharedPtr< NodeListSelectNodes (String xpath)
 Selects a list of nodes matching the XPath expression. More...
 
SharedPtr< NodeSelectSingleNode (String xpath)
 Selects the first Node that matches the XPath expression. More...
 
- Public Member Functions inherited from Node
virtual bool Accept (SharedPtr< DocumentVisitor > visitor)=0
 Accepts a visitor. More...
 
SharedPtr< NodeClone (bool isCloneChildren)
 
virtual SharedPtr< DocumentBaseget_Document () const
 Gets the document to which this node belongs. More...
 
SharedPtr< Nodeget_NextSibling ()
 Gets the node immediately following this node. More...
 
virtual NodeType get_NodeType () const =0
 Gets the type of this node. More...
 
SharedPtr< CompositeNodeget_ParentNode ()
 Gets the immediate parent of this node. More...
 
SharedPtr< Nodeget_PreviousSibling ()
 Gets the node immediately preceding this node. More...
 
SharedPtr< Rangeget_Range ()
 Returns a Range object that represents the portion of a document that is contained in this node. More...
 
SharedPtr< CompositeNodeGetAncestor (NodeType ancestorType)
 Gets the first ancestor of the specified NodeType. More...
 
template<typename T >
GetAncestorOf ()
 
SharedPtr< NodeNextPreOrder (SharedPtr< Node > rootNode)
 Gets next node according to the pre-order tree traversal algorithm. More...
 
SharedPtr< NodePreviousPreOrder (SharedPtr< Node > rootNode)
 Gets the previous node according to the pre-order tree traversal algorithm. More...
 
void Remove ()
 Removes itself from the parent. More...
 
String ToString (SaveFormat saveFormat)
 Exports the content of the node into a string in the specified format. More...
 
String ToString (SharedPtr< SaveOptions > saveOptions)
 Exports the content of the node into a string using the specified save options. More...
 
- Public Member Functions inherited from Object
ASPOSECPP_SHARED_API Object ()
 
ASPOSECPP_SHARED_API Object (Object const &x)
 
virtual ASPOSECPP_SHARED_API ~Object ()
 
virtual ASPOSECPP_SHARED_API bool Equals (ptr obj)
 
Detail::SmartPtrCounter * GetCounter ()
 
virtual ASPOSECPP_SHARED_API int GetHashCode () const
 
virtual ASPOSECPP_SHARED_API const TypeInfoGetType () const
 
virtual ASPOSECPP_SHARED_API bool Is (const TypeInfo &targetType) const
 
ASPOSECPP_SHARED_API void Lock ()
 
virtual ASPOSECPP_SHARED_API ptr MemberwiseClone () const
 
Objectoperator= (Object const &x)
 
bool ReferenceEquals (String const &str, std::nullptr_t)
 
bool ReferenceEquals (String const &str1, String const &str2)
 
int RemovedSharedRefs (int count)
 
virtual ASPOSECPP_SHARED_API void SetTemplateWeakPtr (unsigned int argument)
 
int SharedCount () const
 
ObjectSharedRefAdded ()
 
int SharedRefRemovedSafe ()
 
virtual ASPOSECPP_SHARED_API String ToString () const
 
ASPOSECPP_SHARED_API void Unlock ()
 
Detail::SmartPtrCounter * WeakRefAdded ()
 
void WeakRefRemoved ()
 
- Public Member Functions inherited from System::Collections::Generic::IEnumerable< System::SharedPtr< Aspose::Words::Node > >
EnumeratorBasedIterator< T, IEnumerator< T > > begin () noexcept
 
EnumeratorBasedIterator< T, IEnumerator< T > > cbegin () noexcept
 
EnumeratorBasedIterator< T, IEnumerator< T > > cend () noexcept
 
EnumeratorBasedIterator< T, IEnumerator< T > > end () noexcept
 
bool LINQ_All (std::function< bool(T)> predicate)
 
bool LINQ_Any ()
 
bool LINQ_Any (std::function< bool(T)> predicate)
 
SharedPtr< IEnumerable< ResultType > > LINQ_Cast ()
 
SharedPtr< IEnumerable< Result > > LINQ_Cast ()
 
bool LINQ_Contains (T value)
 
int LINQ_Count ()
 
LINQ_ElementAt (int index)
 
LINQ_First ()
 
LINQ_FirstOrDefault ()
 
LINQ_FirstOrDefault (std::function< bool(T)> predicate)
 
LINQ_Last ()
 
LINQ_LastOrDefault ()
 
SharedPtr< IEnumerable< ResultType > > LINQ_OfType ()
 
SharedPtr< IEnumerable< Result > > LINQ_OfType ()
 
SharedPtr< IEnumerable< Result > > LINQ_Select (const Func< Source, Result > &selector)
 
SharedPtr< IEnumerable< ResultType > > LINQ_Select (const Func< T, ResultType > &selector)
 
ArrayPtr< T > LINQ_ToArray ()
 
SharedPtr< List< T > > LINQ_ToList ()
 
SharedPtr< IEnumerable< T > > LINQ_Where (std::function< bool(T)> predicate)
 

Additional Inherited Members

- Public Types inherited from Object
typedef SmartPtr< Objectptr
 
typedef System::Details::SharedMembersType shared_members_type
 
- Public Types inherited from System::Collections::Generic::IEnumerable< System::SharedPtr< Aspose::Words::Node > >
typedef IEnumerator< T > IEnumeratorType
 
typedef T ValueType
 
- Static Public Member Functions inherited from Node
static String NodeTypeToString (NodeType nodeType)
 A utility method that converts a node type enum value into a user friendly string. More...
 
- Static Public Member Functions inherited from Object
bool Equals (double const &objA, double const &objB)
 
bool Equals (float const &objA, float const &objB)
 
static std::enable_if<!IsSmartPtr< T1 >::value &&!IsSmartPtr< T2 >::value, bool >::type Equals (T1 const &objA, T2 const &objB)
 
static std::enable_if< IsSmartPtr< T1 >::value &&IsSmartPtr< T2 >::value, bool >::type Equals (T1 const &objA, T2 const &objB)
 
static bool ReferenceEquals (ptr const &objA, ptr const &objB)
 
static std::enable_if<!IsSmartPtr< T >::value, bool >::type ReferenceEquals (T const &objA, std::nullptr_t)
 
static std::enable_if<!IsSmartPtr< T >::value, bool >::type ReferenceEquals (T const &objA, T const &objB)
 
static const TypeInfoType ()
 

Member Function Documentation

◆ AppendChild()

System::SharedPtr<Aspose::Words::Node> Aspose::Words::CompositeNode::AppendChild ( 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.

Parameters
newChildThe node to add.
Returns
The node added.

◆ get_ChildNodes()

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.

◆ get_Container()

System::SharedPtr<Aspose::Words::CompositeNode> Aspose::Words::CompositeNode::get_Container ( )

◆ get_Count()

int32_t Aspose::Words::CompositeNode::get_Count ( )

Gets the number of immediate children of this node.

◆ get_FirstChild()

System::SharedPtr<Aspose::Words::Node> Aspose::Words::CompositeNode::get_FirstChild ( ) const

Gets the first child of the node.

If there is no first child node, a null is returned.

◆ get_HasChildNodes()

bool Aspose::Words::CompositeNode::get_HasChildNodes ( )

Returns true if this node has any child nodes.

◆ get_IsComposite()

virtual bool Aspose::Words::CompositeNode::get_IsComposite ( )
virtual

Returns true as this node can have child nodes.

Reimplemented from Aspose::Words::Node.

◆ get_LastChild()

System::SharedPtr<Aspose::Words::Node> Aspose::Words::CompositeNode::get_LastChild ( ) const

Gets the last child of the node.

If there is no last child node, a null is returned.

◆ GetChild()

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.

Parameters
nodeTypeSpecifies the type of the child node.
indexZero 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.
isDeepTrue to select from all child nodes recursively. False to select only among immediate children. See remarks for more info.
Returns
The child node that matches the criteria or null if no matching node is found.

Note that markup nodes (StructuredDocumentTag and SmartTag) are traversed even when isDeep = false and GetChild is invoked for non-markup node type. For example if the first run in a para is wrapped in a StructuredDocumentTag, it will still be returned by GetChild(NodeType.Run, 0, false).

◆ GetChildNodes()

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.

Parameters
nodeTypeSpecifies the type of nodes to select.
isDeepTrue to select from all child nodes recursively. False to select only among immediate children.
Returns
A live collection of child nodes of the specified type.

◆ GetCurrentNode()

System::SharedPtr<Aspose::Words::Node> Aspose::Words::CompositeNode::GetCurrentNode ( )

◆ GetEnumerator()

System::SharedPtr<System::Collections::Generic::IEnumerator<System::SharedPtr<Aspose::Words::Node> > > Aspose::Words::CompositeNode::GetEnumerator ( )
virtual

Provides support for the for each style iteration over the child nodes of this node.

Implements System::Collections::Generic::IEnumerable< System::SharedPtr< Aspose::Words::Node > >.

◆ GetNextMatchingNode()

System::SharedPtr<Aspose::Words::Node> Aspose::Words::CompositeNode::GetNextMatchingNode ( System::SharedPtr< Aspose::Words::Node curNode)

◆ GetText()

virtual System::String Aspose::Words::CompositeNode::GetText ( )
virtual

Gets the text of this node and of all its children.

The returned string includes all control and special characters as described in ControlChar.

Reimplemented from Aspose::Words::Node.

Reimplemented in Aspose::Words::Paragraph, and Aspose::Words::Tables::Row.

◆ IndexOf()

int32_t Aspose::Words::CompositeNode::IndexOf ( System::SharedPtr< Aspose::Words::Node child)

Returns the index of the specified child node in the child node array.

Returns -1 if the node is not found in the child nodes.

◆ InsertAfter()

System::SharedPtr<Aspose::Words::Node> Aspose::Words::CompositeNode::InsertAfter ( System::SharedPtr< Aspose::Words::Node newChild,
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.

Parameters
newChildThe Node to insert.
refChildThe Node that is the reference node. The newNode is placed after the refNode.
Returns
The inserted node.

◆ InsertBefore()

System::SharedPtr<Aspose::Words::Node> Aspose::Words::CompositeNode::InsertBefore ( System::SharedPtr< Aspose::Words::Node newChild,
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.

Parameters
newChildThe Node to insert.
refChildThe Node that is the reference node. The newChild is placed before this node.
Returns
The inserted node.

◆ PrependChild()

System::SharedPtr<Aspose::Words::Node> Aspose::Words::CompositeNode::PrependChild ( 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.

Parameters
newChildThe node to add.
Returns
The node added.

◆ RemoveAllChildren()

void Aspose::Words::CompositeNode::RemoveAllChildren ( )

Removes all the child nodes of the current node.

◆ RemoveChild()

System::SharedPtr<Aspose::Words::Node> Aspose::Words::CompositeNode::RemoveChild ( System::SharedPtr< Aspose::Words::Node oldChild)

Removes the specified child node.

The parent of oldChild is set to null after the node is removed.

Parameters
oldChildThe node to remove.
Returns
The removed node.

◆ RemoveSmartTags()

void Aspose::Words::CompositeNode::RemoveSmartTags ( )

Removes all SmartTag descendant nodes of the current node.

This method does not remove the content of the smart tags.

◆ SelectNodes()

System::SharedPtr<Aspose::Words::NodeList> Aspose::Words::CompositeNode::SelectNodes ( 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.

Parameters
xpathThe XPath expression.
Returns
A list of nodes matching the XPath query.

◆ SelectSingleNode()

System::SharedPtr<Aspose::Words::Node> Aspose::Words::CompositeNode::SelectSingleNode ( 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.

Parameters
xpathThe XPath expression.
Returns
The first Node that matches the XPath query or null if no matching node is found.