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.
Examples

Shows how to traverse through a composite node's collection of child nodes.

auto doc = MakeObject<Document>();
// Add two runs and one shape as child nodes to the first paragraph of this document.
auto paragraph = System::DynamicCast<Paragraph>(doc->GetChild(NodeType::Paragraph, 0, true));
paragraph->AppendChild(MakeObject<Run>(doc, u"Hello world! "));
auto shape = MakeObject<Shape>(doc, ShapeType::Rectangle);
shape->set_Width(200);
shape->set_Height(200);
// Note that the 'CustomNodeId' is not saved to an output file and exists only during the node lifetime.
shape->set_CustomNodeId(100);
shape->set_WrapType(WrapType::Inline);
paragraph->AppendChild(shape);
paragraph->AppendChild(MakeObject<Run>(doc, u"Hello again!"));
// Iterate through the paragraph's collection of immediate children,
// and print any runs or shapes that we find within.
SharedPtr<NodeCollection> children = paragraph->get_ChildNodes();
ASSERT_EQ(3, paragraph->get_ChildNodes()->get_Count());
for (const auto& child : System::IterateOver(children))
{
switch (child->get_NodeType())
{
std::cout << "Run contents:" << std::endl;
std::cout << "\t\"" << child->GetText().Trim() << "\"" << std::endl;
break;
auto childShape = System::DynamicCast<Shape>(child);
std::cout << "Shape:" << std::endl;
std::cout << String::Format(u"\t{0}, {1}x{2}", childShape->get_ShapeType(), childShape->get_Width(), childShape->get_Height()) << std::endl;
ASSERT_EQ(100, shape->get_CustomNodeId());
break;
}
default:
break;
}
}

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

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

Public Member Functions

SharedPtr< NodeAppendChild (const 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...
 
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...
 
bool get_IsComposite () override
 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< 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 TypeInfoGetType () const override
 
int32_t IndexOf (const SharedPtr< Node > &child)
 Returns the index of the specified child node in the child node array. More...
 
SharedPtr< NodeInsertAfter (const SharedPtr< Node > &newChild, const SharedPtr< Node > &refChild)
 Inserts the specified node immediately after the specified reference node. More...
 
SharedPtr< NodeInsertBefore (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< NodePrependChild (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< NodeRemoveChild (const SharedPtr< Node > &oldChild)
 Removes the specified child node. More...
 
void RemoveSmartTags ()
 Removes all SmartTag descendant nodes of the current node. More...
 
SharedPtr< NodeListSelectNodes (const String &xpath)
 Selects a list of nodes matching the XPath expression. More...
 
SharedPtr< NodeSelectSingleNode (const 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)
 Creates a duplicate of the node. More...
 
int32_t get_CustomNodeId () const
 Specifies custom node identifier. More...
 
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 (const SharedPtr< Node > &rootNode)
 Gets next node according to the pre-order tree traversal algorithm. More...
 
SharedPtr< NodePreviousPreOrder (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 TypeInfoType ()
 
- 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 const TypeInfoType ()
 

Member Function Documentation

◆ AppendChild()

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.

Parameters
newChildThe node to add.
Returns
The node added.
Examples

Shows how to construct an Aspose.Words document by hand.

auto doc = MakeObject<Document>();
// A blank document contains one section, one body and one paragraph.
// Call the "RemoveAllChildren" method to remove all those nodes,
// and end up with a document node with no children.
doc->RemoveAllChildren();
// This document now has no composite child nodes that we can add content to.
// If we wish to edit it, we will need to repopulate its node collection.
// First, create a new section, and then append it as a child to the root document node.
auto section = MakeObject<Section>(doc);
doc->AppendChild(section);
// Set some page setup properties for the section.
section->get_PageSetup()->set_SectionStart(SectionStart::NewPage);
section->get_PageSetup()->set_PaperSize(PaperSize::Letter);
// A section needs a body, which will contain and display all its contents
// on the page between the section's header and footer.
auto body = MakeObject<Body>(doc);
section->AppendChild(body);
// Create a paragraph, set some formatting properties, and then append it as a child to the body.
auto para = MakeObject<Paragraph>(doc);
para->get_ParagraphFormat()->set_StyleName(u"Heading 1");
para->get_ParagraphFormat()->set_Alignment(ParagraphAlignment::Center);
body->AppendChild(para);
// Finally, add some content to do the document. Create a run,
// set its appearance and contents, and then append it as a child to the paragraph.
auto run = MakeObject<Run>(doc);
run->set_Text(u"Hello World!");
run->get_Font()->set_Color(System::Drawing::Color::get_Red());
para->AppendChild(run);
ASSERT_EQ(u"Hello World!", doc->GetText().Trim());
doc->Save(ArtifactsDir + u"Section.CreateManually.docx");

◆ 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.

Examples

Shows how to traverse through a composite node's collection of child nodes.

auto doc = MakeObject<Document>();
// Add two runs and one shape as child nodes to the first paragraph of this document.
auto paragraph = System::DynamicCast<Paragraph>(doc->GetChild(NodeType::Paragraph, 0, true));
paragraph->AppendChild(MakeObject<Run>(doc, u"Hello world! "));
auto shape = MakeObject<Shape>(doc, ShapeType::Rectangle);
shape->set_Width(200);
shape->set_Height(200);
// Note that the 'CustomNodeId' is not saved to an output file and exists only during the node lifetime.
shape->set_CustomNodeId(100);
shape->set_WrapType(WrapType::Inline);
paragraph->AppendChild(shape);
paragraph->AppendChild(MakeObject<Run>(doc, u"Hello again!"));
// Iterate through the paragraph's collection of immediate children,
// and print any runs or shapes that we find within.
SharedPtr<NodeCollection> children = paragraph->get_ChildNodes();
ASSERT_EQ(3, paragraph->get_ChildNodes()->get_Count());
for (const auto& child : System::IterateOver(children))
{
switch (child->get_NodeType())
{
std::cout << "Run contents:" << std::endl;
std::cout << "\t\"" << child->GetText().Trim() << "\"" << std::endl;
break;
auto childShape = System::DynamicCast<Shape>(child);
std::cout << "Shape:" << std::endl;
std::cout << String::Format(u"\t{0}, {1}x{2}", childShape->get_ShapeType(), childShape->get_Width(), childShape->get_Height()) << std::endl;
ASSERT_EQ(100, shape->get_CustomNodeId());
break;
}
default:
break;
}
}

◆ get_Count()

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

Gets the number of immediate children of this node.

Examples

Shows how to add, update and delete child nodes in a CompositeNode's collection of children.

auto doc = MakeObject<Document>();
// An empty document, by default, has one paragraph.
ASSERT_EQ(1, doc->get_FirstSection()->get_Body()->get_Paragraphs()->get_Count());
// Composite nodes such as our paragraph can contain other composite and inline nodes as children.
SharedPtr<Paragraph> paragraph = doc->get_FirstSection()->get_Body()->get_FirstParagraph();
auto paragraphText = MakeObject<Run>(doc, u"Initial text. ");
paragraph->AppendChild(paragraphText);
// Create three more run nodes.
auto run1 = MakeObject<Run>(doc, u"Run 1. ");
auto run2 = MakeObject<Run>(doc, u"Run 2. ");
auto run3 = MakeObject<Run>(doc, u"Run 3. ");
// The document body will not display these runs until we insert them into a composite node
// that itself is a part of the document's node tree, as we did with the first run.
// We can determine where the text contents of nodes that we insert
// appears in the document by specifying an insertion location relative to another node in the paragraph.
ASSERT_EQ(u"Initial text.", paragraph->GetText().Trim());
// Insert the second run into the paragraph in front of the initial run.
paragraph->InsertBefore(run2, paragraphText);
ASSERT_EQ(u"Run 2. Initial text.", paragraph->GetText().Trim());
// Insert the third run after the initial run.
paragraph->InsertAfter(run3, paragraphText);
ASSERT_EQ(u"Run 2. Initial text. Run 3.", paragraph->GetText().Trim());
// Insert the first run to the start of the paragraph's child nodes collection.
paragraph->PrependChild(run1);
ASSERT_EQ(u"Run 1. Run 2. Initial text. Run 3.", paragraph->GetText().Trim());
ASSERT_EQ(4, paragraph->GetChildNodes(NodeType::Any, true)->get_Count());
// We can modify the contents of the run by editing and deleting existing child nodes.
(System::DynamicCast<Run>(paragraph->GetChildNodes(NodeType::Run, true)->idx_get(1)))->set_Text(u"Updated run 2. ");
paragraph->GetChildNodes(NodeType::Run, true)->Remove(paragraphText);
ASSERT_EQ(u"Run 1. Updated run 2. Run 3.", paragraph->GetText().Trim());
ASSERT_EQ(3, paragraph->GetChildNodes(NodeType::Any, true)->get_Count());

◆ get_FirstChild()

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

Gets the first child of the node.

Examples

Shows how to traverse a composite node's tree of child nodes.

void RecurseChildren()
{
auto doc = MakeObject<Document>(MyDir + u"Paragraphs.docx");
// Any node that can contain child nodes, such as the document itself, is composite.
ASSERT_TRUE(doc->get_IsComposite());
// Invoke the recursive function that will go through and print all the child nodes of a composite node.
TraverseAllNodes(doc, 0);
}
void TraverseAllNodes(SharedPtr<CompositeNode> parentNode, int depth)
{
for (SharedPtr<Node> childNode = parentNode->get_FirstChild(); childNode != nullptr; childNode = childNode->get_NextSibling())
{
std::cout << (String(u'\t', depth)) << Node::NodeTypeToString(childNode->get_NodeType());
// Recurse into the node if it is a composite node. Otherwise, print its contents if it is an inline node.
if (childNode->get_IsComposite())
{
std::cout << std::endl;
TraverseAllNodes(System::DynamicCast<CompositeNode>(childNode), depth + 1);
}
else if (System::ObjectExt::Is<Inline>(childNode))
{
std::cout << " - \"" << childNode->GetText().Trim() << "\"" << std::endl;
}
else
{
std::cout << std::endl;
}
}
}

Shows how to use a node's NextSibling property to enumerate through its immediate children.

auto doc = MakeObject<Document>(MyDir + u"Paragraphs.docx");
for (SharedPtr<Node> node = doc->get_FirstSection()->get_Body()->get_FirstChild(); node != nullptr; node = node->get_NextSibling())
{
std::cout << std::endl;
std::cout << "Node type: " << Node::NodeTypeToString(node->get_NodeType()) << std::endl;
String contents = node->GetText().Trim();
std::cout << (contents == String::Empty ? u"This node contains no text" : String::Format(u"Contents: \"{0}\"", node->GetText().Trim()))
<< std::endl;
}

◆ get_HasChildNodes()

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

Returns true if this node has any child nodes.

Examples

Shows how to combine the rows from two tables into one.

auto doc = MakeObject<Document>(MyDir + u"Tables.docx");
// Below are two ways of getting a table from a document.
// 1 - From the "Tables" collection of a Body node:
SharedPtr<Table> firstTable = doc->get_FirstSection()->get_Body()->get_Tables()->idx_get(0);
// 2 - Using the "GetChild" method:
auto secondTable = System::DynamicCast<Table>(doc->GetChild(NodeType::Table, 1, true));
// Append all rows from the current table to the next.
while (secondTable->get_HasChildNodes())
{
firstTable->get_Rows()->Add(secondTable->get_FirstRow());
}
// Remove the empty table container.
secondTable->Remove();
doc->Save(ArtifactsDir + u"Table.CombineTables.docx");

◆ get_IsComposite()

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

Returns true as this node can have child nodes.

Examples

Shows how to traverse a composite node's tree of child nodes.

void RecurseChildren()
{
auto doc = MakeObject<Document>(MyDir + u"Paragraphs.docx");
// Any node that can contain child nodes, such as the document itself, is composite.
ASSERT_TRUE(doc->get_IsComposite());
// Invoke the recursive function that will go through and print all the child nodes of a composite node.
TraverseAllNodes(doc, 0);
}
void TraverseAllNodes(SharedPtr<CompositeNode> parentNode, int depth)
{
for (SharedPtr<Node> childNode = parentNode->get_FirstChild(); childNode != nullptr; childNode = childNode->get_NextSibling())
{
std::cout << (String(u'\t', depth)) << Node::NodeTypeToString(childNode->get_NodeType());
// Recurse into the node if it is a composite node. Otherwise, print its contents if it is an inline node.
if (childNode->get_IsComposite())
{
std::cout << std::endl;
TraverseAllNodes(System::DynamicCast<CompositeNode>(childNode), depth + 1);
}
else if (System::ObjectExt::Is<Inline>(childNode))
{
std::cout << " - \"" << childNode->GetText().Trim() << "\"" << std::endl;
}
else
{
std::cout << std::endl;
}
}
}

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.

Examples

Shows how to use of methods of Node and CompositeNode to remove a section before the last section in the document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Section 1 text.");
builder->InsertBreak(BreakType::SectionBreakContinuous);
builder->Writeln(u"Section 2 text.");
// Both sections are siblings of each other.
auto lastSection = System::DynamicCast<Section>(doc->get_LastChild());
auto firstSection = System::DynamicCast<Section>(lastSection->get_PreviousSibling());
// Remove a section based on its sibling relationship with another section.
if (lastSection->get_PreviousSibling() != nullptr)
{
doc->RemoveChild(firstSection);
}
// The section we removed was the first one, leaving the document with only the second.
ASSERT_EQ(u"Section 2 text.", doc->GetText().Trim());

◆ 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.
Examples

Shows how to apply the properties of a table's style directly to the table's elements.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<Table> table = builder->StartTable();
builder->InsertCell();
builder->Write(u"Hello world!");
builder->EndTable();
auto tableStyle = System::DynamicCast<TableStyle>(doc->get_Styles()->Add(StyleType::Table, u"MyTableStyle1"));
tableStyle->set_RowStripe(3);
tableStyle->set_CellSpacing(5);
tableStyle->get_Shading()->set_BackgroundPatternColor(System::Drawing::Color::get_AntiqueWhite());
tableStyle->get_Borders()->set_Color(System::Drawing::Color::get_Blue());
tableStyle->get_Borders()->set_LineStyle(LineStyle::DotDash);
table->set_Style(tableStyle);
// This method concerns table style properties such as the ones we set above.
doc->ExpandTableStylesToDirectFormatting();
doc->Save(ArtifactsDir + u"Document.TableStyleToDirectFormatting.docx");

Shows how to traverse through a composite node's collection of child nodes.

auto doc = MakeObject<Document>();
// Add two runs and one shape as child nodes to the first paragraph of this document.
auto paragraph = System::DynamicCast<Paragraph>(doc->GetChild(NodeType::Paragraph, 0, true));
paragraph->AppendChild(MakeObject<Run>(doc, u"Hello world! "));
auto shape = MakeObject<Shape>(doc, ShapeType::Rectangle);
shape->set_Width(200);
shape->set_Height(200);
// Note that the 'CustomNodeId' is not saved to an output file and exists only during the node lifetime.
shape->set_CustomNodeId(100);
shape->set_WrapType(WrapType::Inline);
paragraph->AppendChild(shape);
paragraph->AppendChild(MakeObject<Run>(doc, u"Hello again!"));
// Iterate through the paragraph's collection of immediate children,
// and print any runs or shapes that we find within.
SharedPtr<NodeCollection> children = paragraph->get_ChildNodes();
ASSERT_EQ(3, paragraph->get_ChildNodes()->get_Count());
for (const auto& child : System::IterateOver(children))
{
switch (child->get_NodeType())
{
std::cout << "Run contents:" << std::endl;
std::cout << "\t\"" << child->GetText().Trim() << "\"" << std::endl;
break;
auto childShape = System::DynamicCast<Shape>(child);
std::cout << "Shape:" << std::endl;
std::cout << String::Format(u"\t{0}, {1}x{2}", childShape->get_ShapeType(), childShape->get_Width(), childShape->get_Height()) << std::endl;
ASSERT_EQ(100, shape->get_CustomNodeId());
break;
}
default:
break;
}
}

◆ 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.
Examples

Shows how to print all of a document's comments and their replies.

auto doc = MakeObject<Document>(MyDir + u"Comments.docx");
SharedPtr<NodeCollection> comments = doc->GetChildNodes(NodeType::Comment, true);
// If a comment has no ancestor, it is a "top-level" comment as opposed to a reply-type comment.
// Print all top-level comments along with any replies they may have.
auto hasNullAncestor = [](SharedPtr<Comment> c)
{
return c->get_Ancestor() == nullptr;
};
for (auto comment : System::IterateOver(comments->LINQ_OfType<SharedPtr<Comment>>()->LINQ_Where(hasNullAncestor)))
{
std::cout << "Top-level comment:" << std::endl;
std::cout << "\t\"" << comment->GetText().Trim() << "\", by " << comment->get_Author() << std::endl;
std::cout << "Has " << comment->get_Replies()->get_Count() << " replies" << std::endl;
for (const auto& commentReply : System::IterateOver<Comment>(comment->get_Replies()))
{
std::cout << "\t\"" << commentReply->GetText().Trim() << "\", by " << commentReply->get_Author() << std::endl;
}
std::cout << std::endl;
}

Shows how to extract images from a document, and save them to the local file system as individual files.

auto doc = MakeObject<Document>(MyDir + u"Images.docx");
// Get the collection of shapes from the document,
// and save the image data of every shape with an image as a file to the local file system.
SharedPtr<NodeCollection> shapes = doc->GetChildNodes(NodeType::Shape, true);
ASSERT_EQ(9, shapes->LINQ_Count([](SharedPtr<Node> s) { return (System::DynamicCast<Shape>(s))->get_HasImage(); }));
int imageIndex = 0;
for (const auto& shape : System::IterateOver(shapes->LINQ_OfType<SharedPtr<Shape>>()))
{
if (shape->get_HasImage())
{
// The image data of shapes may contain images of many possible image formats.
// We can determine a file extension for each image automatically, based on its format.
String imageFileName =
String::Format(u"File.ExtractImages.{0}{1}", imageIndex, FileFormatUtil::ImageTypeToExtension(shape->get_ImageData()->get_ImageType()));
shape->get_ImageData()->Save(ArtifactsDir + imageFileName);
imageIndex++;
}
}

Shows how to add, update and delete child nodes in a CompositeNode's collection of children.

auto doc = MakeObject<Document>();
// An empty document, by default, has one paragraph.
ASSERT_EQ(1, doc->get_FirstSection()->get_Body()->get_Paragraphs()->get_Count());
// Composite nodes such as our paragraph can contain other composite and inline nodes as children.
SharedPtr<Paragraph> paragraph = doc->get_FirstSection()->get_Body()->get_FirstParagraph();
auto paragraphText = MakeObject<Run>(doc, u"Initial text. ");
paragraph->AppendChild(paragraphText);
// Create three more run nodes.
auto run1 = MakeObject<Run>(doc, u"Run 1. ");
auto run2 = MakeObject<Run>(doc, u"Run 2. ");
auto run3 = MakeObject<Run>(doc, u"Run 3. ");
// The document body will not display these runs until we insert them into a composite node
// that itself is a part of the document's node tree, as we did with the first run.
// We can determine where the text contents of nodes that we insert
// appears in the document by specifying an insertion location relative to another node in the paragraph.
ASSERT_EQ(u"Initial text.", paragraph->GetText().Trim());
// Insert the second run into the paragraph in front of the initial run.
paragraph->InsertBefore(run2, paragraphText);
ASSERT_EQ(u"Run 2. Initial text.", paragraph->GetText().Trim());
// Insert the third run after the initial run.
paragraph->InsertAfter(run3, paragraphText);
ASSERT_EQ(u"Run 2. Initial text. Run 3.", paragraph->GetText().Trim());
// Insert the first run to the start of the paragraph's child nodes collection.
paragraph->PrependChild(run1);
ASSERT_EQ(u"Run 1. Run 2. Initial text. Run 3.", paragraph->GetText().Trim());
ASSERT_EQ(4, paragraph->GetChildNodes(NodeType::Any, true)->get_Count());
// We can modify the contents of the run by editing and deleting existing child nodes.
(System::DynamicCast<Run>(paragraph->GetChildNodes(NodeType::Run, true)->idx_get(1)))->set_Text(u"Updated run 2. ");
paragraph->GetChildNodes(NodeType::Run, true)->Remove(paragraphText);
ASSERT_EQ(u"Run 1. Updated run 2. Run 3.", paragraph->GetText().Trim());
ASSERT_EQ(3, paragraph->GetChildNodes(NodeType::Any, true)->get_Count());

◆ GetEnumerator()

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

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

Examples

Shows how to traverse through a composite node's collection of child nodes.

auto doc = MakeObject<Document>();
// Add two runs and one shape as child nodes to the first paragraph of this document.
auto paragraph = System::DynamicCast<Paragraph>(doc->GetChild(NodeType::Paragraph, 0, true));
paragraph->AppendChild(MakeObject<Run>(doc, u"Hello world! "));
auto shape = MakeObject<Shape>(doc, ShapeType::Rectangle);
shape->set_Width(200);
shape->set_Height(200);
// Note that the 'CustomNodeId' is not saved to an output file and exists only during the node lifetime.
shape->set_CustomNodeId(100);
shape->set_WrapType(WrapType::Inline);
paragraph->AppendChild(shape);
paragraph->AppendChild(MakeObject<Run>(doc, u"Hello again!"));
// Iterate through the paragraph's collection of immediate children,
// and print any runs or shapes that we find within.
SharedPtr<NodeCollection> children = paragraph->get_ChildNodes();
ASSERT_EQ(3, paragraph->get_ChildNodes()->get_Count());
for (const auto& child : System::IterateOver(children))
{
switch (child->get_NodeType())
{
std::cout << "Run contents:" << std::endl;
std::cout << "\t\"" << child->GetText().Trim() << "\"" << std::endl;
break;
auto childShape = System::DynamicCast<Shape>(child);
std::cout << "Shape:" << std::endl;
std::cout << String::Format(u"\t{0}, {1}x{2}", childShape->get_ShapeType(), childShape->get_Width(), childShape->get_Height()) << std::endl;
ASSERT_EQ(100, shape->get_CustomNodeId());
break;
}
default:
break;
}
}

◆ GetText()

System::String Aspose::Words::CompositeNode::GetText ( )
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.

Examples

Shows the difference between calling the GetText and ToString methods on a node.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->InsertField(u"MERGEFIELD Field");
// GetText will retrieve the visible text as well as field codes and special characters.
ASSERT_EQ(u"\u0013MERGEFIELD Field\u0014«Field»\u0015\u000c", doc->GetText());
// ToString will give us the document's appearance if saved to a passed save format.
ASSERT_EQ(u"«Field»\r\n", doc->ToString(SaveFormat::Text));

Shows how to output all paragraphs in a document that are list items.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->get_ListFormat()->ApplyNumberDefault();
builder->Writeln(u"Numbered list item 1");
builder->Writeln(u"Numbered list item 2");
builder->Writeln(u"Numbered list item 3");
builder->get_ListFormat()->RemoveNumbers();
builder->get_ListFormat()->ApplyBulletDefault();
builder->Writeln(u"Bulleted list item 1");
builder->Writeln(u"Bulleted list item 2");
builder->Writeln(u"Bulleted list item 3");
builder->get_ListFormat()->RemoveNumbers();
SharedPtr<NodeCollection> paras = doc->GetChildNodes(NodeType::Paragraph, true);
for (auto para : System::IterateOver(
paras->LINQ_OfType<SharedPtr<Paragraph>>()->LINQ_Where([](SharedPtr<Paragraph> p) { return p->get_ListFormat()->get_IsListItem(); })))
{
std::cout << String::Format(u"This paragraph belongs to list ID# {0}, number style \"{1}\"", para->get_ListFormat()->get_List()->get_ListId(),
para->get_ListFormat()->get_ListLevel()->get_NumberStyle())
<< std::endl;
std::cout << "\t\"" << para->GetText().Trim() << "\"" << std::endl;
}

Reimplemented from Aspose::Words::Node.

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

◆ GetType()

◆ IndexOf()

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.

Examples

Shows how to get the index of a given child node from its parent.

auto doc = MakeObject<Document>(MyDir + u"Rendering.docx");
SharedPtr<Body> body = doc->get_FirstSection()->get_Body();
// Retrieve the index of the last paragraph in the body of the first section.
ASSERT_EQ(24, body->get_ChildNodes()->IndexOf(body->get_LastParagraph()));

◆ InsertAfter()

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.

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

Shows how to add, update and delete child nodes in a CompositeNode's collection of children.

auto doc = MakeObject<Document>();
// An empty document, by default, has one paragraph.
ASSERT_EQ(1, doc->get_FirstSection()->get_Body()->get_Paragraphs()->get_Count());
// Composite nodes such as our paragraph can contain other composite and inline nodes as children.
SharedPtr<Paragraph> paragraph = doc->get_FirstSection()->get_Body()->get_FirstParagraph();
auto paragraphText = MakeObject<Run>(doc, u"Initial text. ");
paragraph->AppendChild(paragraphText);
// Create three more run nodes.
auto run1 = MakeObject<Run>(doc, u"Run 1. ");
auto run2 = MakeObject<Run>(doc, u"Run 2. ");
auto run3 = MakeObject<Run>(doc, u"Run 3. ");
// The document body will not display these runs until we insert them into a composite node
// that itself is a part of the document's node tree, as we did with the first run.
// We can determine where the text contents of nodes that we insert
// appears in the document by specifying an insertion location relative to another node in the paragraph.
ASSERT_EQ(u"Initial text.", paragraph->GetText().Trim());
// Insert the second run into the paragraph in front of the initial run.
paragraph->InsertBefore(run2, paragraphText);
ASSERT_EQ(u"Run 2. Initial text.", paragraph->GetText().Trim());
// Insert the third run after the initial run.
paragraph->InsertAfter(run3, paragraphText);
ASSERT_EQ(u"Run 2. Initial text. Run 3.", paragraph->GetText().Trim());
// Insert the first run to the start of the paragraph's child nodes collection.
paragraph->PrependChild(run1);
ASSERT_EQ(u"Run 1. Run 2. Initial text. Run 3.", paragraph->GetText().Trim());
ASSERT_EQ(4, paragraph->GetChildNodes(NodeType::Any, true)->get_Count());
// We can modify the contents of the run by editing and deleting existing child nodes.
(System::DynamicCast<Run>(paragraph->GetChildNodes(NodeType::Run, true)->idx_get(1)))->set_Text(u"Updated run 2. ");
paragraph->GetChildNodes(NodeType::Run, true)->Remove(paragraphText);
ASSERT_EQ(u"Run 1. Updated run 2. Run 3.", paragraph->GetText().Trim());
ASSERT_EQ(3, paragraph->GetChildNodes(NodeType::Any, true)->get_Count());

Shows how to replace all textbox shapes with image shapes.

auto doc = MakeObject<Document>(MyDir + u"Textboxes in drawing canvas.docx");
ArrayPtr<SharedPtr<Shape>> shapes = doc->GetChildNodes(NodeType::Shape, true)->LINQ_OfType<SharedPtr<Shape>>()->LINQ_ToArray();
auto isTextBox = [](SharedPtr<Shape> s)
{
return s->get_ShapeType() == ShapeType::TextBox;
};
auto isImage = [](SharedPtr<Shape> s)
{
return s->get_ShapeType() == ShapeType::Image;
};
ASSERT_EQ(3, shapes->LINQ_Count(isTextBox));
ASSERT_EQ(1, shapes->LINQ_Count(isImage));
for (SharedPtr<Shape> shape : shapes)
{
if (shape->get_ShapeType() == ShapeType::TextBox)
{
auto replacementShape = MakeObject<Shape>(doc, ShapeType::Image);
replacementShape->get_ImageData()->SetImage(ImageDir + u"Logo.jpg");
replacementShape->set_Left(shape->get_Left());
replacementShape->set_Top(shape->get_Top());
replacementShape->set_Width(shape->get_Width());
replacementShape->set_Height(shape->get_Height());
replacementShape->set_RelativeHorizontalPosition(shape->get_RelativeHorizontalPosition());
replacementShape->set_RelativeVerticalPosition(shape->get_RelativeVerticalPosition());
replacementShape->set_HorizontalAlignment(shape->get_HorizontalAlignment());
replacementShape->set_VerticalAlignment(shape->get_VerticalAlignment());
replacementShape->set_WrapType(shape->get_WrapType());
replacementShape->set_WrapSide(shape->get_WrapSide());
shape->get_ParentNode()->InsertAfter(replacementShape, shape);
shape->Remove();
}
}
shapes = doc->GetChildNodes(NodeType::Shape, true)->LINQ_OfType<SharedPtr<Shape>>()->LINQ_ToArray();
ASSERT_EQ(0, shapes->LINQ_Count(isTextBox));
ASSERT_EQ(4, shapes->LINQ_Count(isImage));
doc->Save(ArtifactsDir + u"Shape.ReplaceTextboxesWithImages.docx");

◆ InsertBefore()

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.

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

Shows how to add, update and delete child nodes in a CompositeNode's collection of children.

auto doc = MakeObject<Document>();
// An empty document, by default, has one paragraph.
ASSERT_EQ(1, doc->get_FirstSection()->get_Body()->get_Paragraphs()->get_Count());
// Composite nodes such as our paragraph can contain other composite and inline nodes as children.
SharedPtr<Paragraph> paragraph = doc->get_FirstSection()->get_Body()->get_FirstParagraph();
auto paragraphText = MakeObject<Run>(doc, u"Initial text. ");
paragraph->AppendChild(paragraphText);
// Create three more run nodes.
auto run1 = MakeObject<Run>(doc, u"Run 1. ");
auto run2 = MakeObject<Run>(doc, u"Run 2. ");
auto run3 = MakeObject<Run>(doc, u"Run 3. ");
// The document body will not display these runs until we insert them into a composite node
// that itself is a part of the document's node tree, as we did with the first run.
// We can determine where the text contents of nodes that we insert
// appears in the document by specifying an insertion location relative to another node in the paragraph.
ASSERT_EQ(u"Initial text.", paragraph->GetText().Trim());
// Insert the second run into the paragraph in front of the initial run.
paragraph->InsertBefore(run2, paragraphText);
ASSERT_EQ(u"Run 2. Initial text.", paragraph->GetText().Trim());
// Insert the third run after the initial run.
paragraph->InsertAfter(run3, paragraphText);
ASSERT_EQ(u"Run 2. Initial text. Run 3.", paragraph->GetText().Trim());
// Insert the first run to the start of the paragraph's child nodes collection.
paragraph->PrependChild(run1);
ASSERT_EQ(u"Run 1. Run 2. Initial text. Run 3.", paragraph->GetText().Trim());
ASSERT_EQ(4, paragraph->GetChildNodes(NodeType::Any, true)->get_Count());
// We can modify the contents of the run by editing and deleting existing child nodes.
(System::DynamicCast<Run>(paragraph->GetChildNodes(NodeType::Run, true)->idx_get(1)))->set_Text(u"Updated run 2. ");
paragraph->GetChildNodes(NodeType::Run, true)->Remove(paragraphText);
ASSERT_EQ(u"Run 1. Updated run 2. Run 3.", paragraph->GetText().Trim());
ASSERT_EQ(3, paragraph->GetChildNodes(NodeType::Any, true)->get_Count());

◆ Is()

◆ PrependChild()

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.

Parameters
newChildThe node to add.
Returns
The node added.
Examples

Shows how to add, update and delete child nodes in a CompositeNode's collection of children.

auto doc = MakeObject<Document>();
// An empty document, by default, has one paragraph.
ASSERT_EQ(1, doc->get_FirstSection()->get_Body()->get_Paragraphs()->get_Count());
// Composite nodes such as our paragraph can contain other composite and inline nodes as children.
SharedPtr<Paragraph> paragraph = doc->get_FirstSection()->get_Body()->get_FirstParagraph();
auto paragraphText = MakeObject<Run>(doc, u"Initial text. ");
paragraph->AppendChild(paragraphText);
// Create three more run nodes.
auto run1 = MakeObject<Run>(doc, u"Run 1. ");
auto run2 = MakeObject<Run>(doc, u"Run 2. ");
auto run3 = MakeObject<Run>(doc, u"Run 3. ");
// The document body will not display these runs until we insert them into a composite node
// that itself is a part of the document's node tree, as we did with the first run.
// We can determine where the text contents of nodes that we insert
// appears in the document by specifying an insertion location relative to another node in the paragraph.
ASSERT_EQ(u"Initial text.", paragraph->GetText().Trim());
// Insert the second run into the paragraph in front of the initial run.
paragraph->InsertBefore(run2, paragraphText);
ASSERT_EQ(u"Run 2. Initial text.", paragraph->GetText().Trim());
// Insert the third run after the initial run.
paragraph->InsertAfter(run3, paragraphText);
ASSERT_EQ(u"Run 2. Initial text. Run 3.", paragraph->GetText().Trim());
// Insert the first run to the start of the paragraph's child nodes collection.
paragraph->PrependChild(run1);
ASSERT_EQ(u"Run 1. Run 2. Initial text. Run 3.", paragraph->GetText().Trim());
ASSERT_EQ(4, paragraph->GetChildNodes(NodeType::Any, true)->get_Count());
// We can modify the contents of the run by editing and deleting existing child nodes.
(System::DynamicCast<Run>(paragraph->GetChildNodes(NodeType::Run, true)->idx_get(1)))->set_Text(u"Updated run 2. ");
paragraph->GetChildNodes(NodeType::Run, true)->Remove(paragraphText);
ASSERT_EQ(u"Run 1. Updated run 2. Run 3.", paragraph->GetText().Trim());
ASSERT_EQ(3, paragraph->GetChildNodes(NodeType::Any, true)->get_Count());

◆ RemoveAllChildren()

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

Removes all the child nodes of the current node.

Examples

Shows how to construct an Aspose.Words document by hand.

auto doc = MakeObject<Document>();
// A blank document contains one section, one body and one paragraph.
// Call the "RemoveAllChildren" method to remove all those nodes,
// and end up with a document node with no children.
doc->RemoveAllChildren();
// This document now has no composite child nodes that we can add content to.
// If we wish to edit it, we will need to repopulate its node collection.
// First, create a new section, and then append it as a child to the root document node.
auto section = MakeObject<Section>(doc);
doc->AppendChild(section);
// Set some page setup properties for the section.
section->get_PageSetup()->set_SectionStart(SectionStart::NewPage);
section->get_PageSetup()->set_PaperSize(PaperSize::Letter);
// A section needs a body, which will contain and display all its contents
// on the page between the section's header and footer.
auto body = MakeObject<Body>(doc);
section->AppendChild(body);
// Create a paragraph, set some formatting properties, and then append it as a child to the body.
auto para = MakeObject<Paragraph>(doc);
para->get_ParagraphFormat()->set_StyleName(u"Heading 1");
para->get_ParagraphFormat()->set_Alignment(ParagraphAlignment::Center);
body->AppendChild(para);
// Finally, add some content to do the document. Create a run,
// set its appearance and contents, and then append it as a child to the paragraph.
auto run = MakeObject<Run>(doc);
run->set_Text(u"Hello World!");
run->get_Font()->set_Color(System::Drawing::Color::get_Red());
para->AppendChild(run);
ASSERT_EQ(u"Hello World!", doc->GetText().Trim());
doc->Save(ArtifactsDir + u"Section.CreateManually.docx");

◆ RemoveChild()

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.

Parameters
oldChildThe node to remove.
Returns
The removed node.
Examples

Shows how to use of methods of Node and CompositeNode to remove a section before the last section in the document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Section 1 text.");
builder->InsertBreak(BreakType::SectionBreakContinuous);
builder->Writeln(u"Section 2 text.");
// Both sections are siblings of each other.
auto lastSection = System::DynamicCast<Section>(doc->get_LastChild());
auto firstSection = System::DynamicCast<Section>(lastSection->get_PreviousSibling());
// Remove a section based on its sibling relationship with another section.
if (lastSection->get_PreviousSibling() != nullptr)
{
doc->RemoveChild(firstSection);
}
// The section we removed was the first one, leaving the document with only the second.
ASSERT_EQ(u"Section 2 text.", doc->GetText().Trim());

◆ RemoveSmartTags()

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

Removes all SmartTag descendant nodes of the current node.

Examples

Removes all smart tags from descendant nodes of a composite node.

auto doc = MakeObject<Document>(MyDir + u"Smart tags.doc");
ASSERT_EQ(8, doc->GetChildNodes(NodeType::SmartTag, true)->get_Count());
doc->RemoveSmartTags();
ASSERT_EQ(0, doc->GetChildNodes(NodeType::SmartTag, true)->get_Count());

Shows how to create smart tags.

void Create()
{
auto doc = MakeObject<Document>();
// A smart tag appears in a document with Microsoft Word recognizes a part of its text as some form of data,
// such as a name, date, or address, and converts it to a hyperlink that displays a purple dotted underline.
auto smartTag = MakeObject<SmartTag>(doc);
// Smart tags are composite nodes that contain their recognized text in its entirety.
// Add contents to this smart tag manually.
smartTag->AppendChild(MakeObject<Run>(doc, u"May 29, 2019"));
// Microsoft Word may recognize the above contents as being a date.
// Smart tags use the "Element" property to reflect the type of data they contain.
smartTag->set_Element(u"date");
// Some smart tag types process their contents further into custom XML properties.
smartTag->get_Properties()->Add(MakeObject<CustomXmlProperty>(u"Day", String::Empty, u"29"));
smartTag->get_Properties()->Add(MakeObject<CustomXmlProperty>(u"Month", String::Empty, u"5"));
smartTag->get_Properties()->Add(MakeObject<CustomXmlProperty>(u"Year", String::Empty, u"2019"));
// Set the smart tag's URI to the default value.
smartTag->set_Uri(u"urn:schemas-microsoft-com:office:smarttags");
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(smartTag);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(MakeObject<Run>(doc, u" is a date. "));
// Create another smart tag for a stock ticker.
smartTag = MakeObject<SmartTag>(doc);
smartTag->set_Element(u"stockticker");
smartTag->set_Uri(u"urn:schemas-microsoft-com:office:smarttags");
smartTag->AppendChild(MakeObject<Run>(doc, u"MSFT"));
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(smartTag);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(MakeObject<Run>(doc, u" is a stock ticker."));
// Print all the smart tags in our document using a document visitor.
doc->Accept(MakeObject<ExSmartTag::SmartTagPrinter>());
// Older versions of Microsoft Word support smart tags.
doc->Save(ArtifactsDir + u"SmartTag.Create.doc");
// Use the "RemoveSmartTags" method to remove all smart tags from a document.
ASSERT_EQ(2, doc->GetChildNodes(NodeType::SmartTag, true)->get_Count());
doc->RemoveSmartTags();
ASSERT_EQ(0, doc->GetChildNodes(NodeType::SmartTag, true)->get_Count());
}
class SmartTagPrinter : public DocumentVisitor
{
public:
VisitorAction VisitSmartTagStart(SharedPtr<SmartTag> smartTag) override
{
std::cout << "Smart tag type: " << smartTag->get_Element() << std::endl;
}
VisitorAction VisitSmartTagEnd(SharedPtr<SmartTag> smartTag) override
{
std::cout << "\tContents: \"" << smartTag->ToString(SaveFormat::Text) << "\"" << std::endl;
if (smartTag->get_Properties()->get_Count() == 0)
{
std::cout << "\tContains no properties" << std::endl;
}
else
{
std::cout << "\tProperties: ";
auto properties = MakeArray<String>(smartTag->get_Properties()->get_Count());
int index = 0;
for (const auto& cxp : System::IterateOver(smartTag->get_Properties()))
{
properties[index++] = String::Format(u"\"{0}\" = \"{1}\"", cxp->get_Name(), cxp->get_Value());
}
std::cout << String::Join(u", ", properties) << std::endl;
}
}
};

◆ SelectNodes()

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.

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

◆ SelectSingleNode()

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.

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

◆ Type()

static const System::TypeInfo& Aspose::Words::CompositeNode::Type ( )
static