Node Class |
Namespace: Aspose.Words
The Node type exposes the following members.
Name | Description | |
---|---|---|
Document |
Gets the document to which this node belongs.
| |
IsComposite |
Returns true if this node can contain other nodes.
| |
NextSibling |
Gets the node immediately following this node.
| |
NodeType |
Gets the type of this node.
| |
ParentNode |
Gets the immediate parent of this node.
| |
PreviousSibling |
Gets the node immediately preceding this node.
| |
Range |
Returns a Range object that represents the portion of a document that is contained in this node.
|
Name | Description | |
---|---|---|
Accept |
Accepts a visitor.
| |
Clone | ||
Equals | (Inherited from Object.) | |
GetAncestor(Type) |
Gets the first ancestor of the specified object type.
| |
GetAncestor(NodeType) |
Gets the first ancestor of the specified NodeType.
| |
GetHashCode | (Inherited from Object.) | |
GetText |
Gets the text of this node and of all its children.
| |
GetType | (Inherited from Object.) | |
NextPreOrder |
Gets next node according to the pre-order tree traversal algorithm.
| |
NodeTypeToString |
A utility method that converts a node type enum value into a user friendly string.
| |
PreviousPreOrder |
Gets the previous node according to the pre-order tree traversal algorithm.
| |
Remove |
Removes itself from the parent.
| |
ToString | (Inherited from Object.) | |
ToString(SaveFormat) |
Exports the content of the node into a string in the specified format.
| |
ToString(SaveOptions) |
Exports the content of the node into a string using the specified save options.
|
A document is represented as a tree of nodes, similar to DOM or XmlDocument.
For more info see the Composite design pattern.
The Node class:
Paragraph paragraph = (Paragraph) doc.GetChild(NodeType.Paragraph, 0, true);
// Create a new empty document Document doc = new Document(); // Add some text to the first paragraph Paragraph para = doc.FirstSection.Body.FirstParagraph; para.AppendChild(new Run(doc, "Some text")); // Clone the paragraph and the child nodes Node cloneWithChildren = para.Clone(true); // Only clone the paragraph and no child nodes Node cloneWithoutChildren = para.Clone(false);
// In this example we remove tables from a section body // Get the section that we want to work on Section section = doc.Sections[0]; Body body = section.Body; // Select the first child node in the body Node curNode = body.FirstChild; while (curNode != null) { // Save the pointer to the next sibling node because if the current // node is removed from the parent in the next step, we will have // no way of finding the next node to continue the loop Node nextNode = curNode.NextSibling; // A section body can contain Paragraph and Table nodes // If the node is a Table, remove it from the parent if (curNode.NodeType.Equals(NodeType.Table)) curNode.Remove(); // Continue going through child nodes until null (no more siblings) is reached curNode = nextNode; }