Class CompositeNode

Class CompositeNode

Namespace: Aspose.Note
Assembly: Aspose.Note.dll (25.6.0)

The base generic class for nodes that can contain other nodes.

public abstract class CompositeNode<T> : CompositeNodeBase, INode, ICompositeNode<T>, ICompositeNode, IEnumerable<T>, IEnumerable where T : INode
{
    public void Add(T node)
    {
        if (node == null) throw new ArgumentNullException(nameof(node));
        if (!_children.Contains(node))
            _children.Add(node);
    }
    IEnumerator<T> IEnumerable<T>.GetEnumerator()
    {
        return _children.OfType<T>().GetEnumerator();
    }
    IEnumerator IEnumerable.GetEnumerator()
    {
        return GetEnumerator();
    }
}

Type Parameters

T

The type of elements in the composite node.

Inheritance

object Node CompositeNodeBase CompositeNode

Implements

INode , ICompositeNode , ICompositeNode , IEnumerable , IEnumerable

Inherited Members

CompositeNodeBase.GetChildNodes(NodeType) , CompositeNodeBase.GetChildNodes() , CompositeNodeBase.CheckDocument(Node) , Node.Accept(DocumentVisitor) , Node.Document , Node.IsComposite , Node.NodeType , Node.ParentNode , Node.PreviousSibling , Node.NextSibling , object.GetType() , object.MemberwiseClone() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()

Constructors

CompositeNode(NodeType)

Initializes a new instance of the Aspose.Note.CompositeNode`1 class.

protected CompositeNode(NodeType nodeType)
   {
   }

Parameters

nodeType NodeType

The type of the node.

Properties

FirstChild

Gets the first child node of this node.

public T FirstChild
   {
      get;
   }

Property Value

T

Examples

Shows how to check if a page is a conflict page(i.e. it has changes that OneNote couldn’t automatically merge).

string dataDir = RunExamples.GetDataDir_Pages();
    Document doc = new Document(dataDir + "Aspose.one", new LoadOptions { LoadHistory = true });
    var history = doc.GetPageHistory(doc.FirstChild);
    for (int i = 0; i < history.Count; i++)
    {
        var historyPage = history[i];
        Console.Write("    {0}. Author: ", i);
        Console.WriteLine("{1}, {2:dd.MM.yyyy hh.mm.ss}",
            historyPage.PageContentRevisionSummary.AuthorMostRecent,
            historyPage.PageContentRevisionSummary.LastModifiedTime);
        Console.Write(historyPage.IsConflictPage ? ", IsConflict: true" : string.Empty);
        if (historyPage.IsConflictPage)
            historyPage.IsConflictPage = false;
    }
    doc.Save(dataDir + "ConflictPageManipulation_out.one", SaveFormat.One);

IsComposite

Checks whether the node is composite. If true then the node can have child nodes.

public override sealed bool IsComposite
    {
        get;
    }

Property Value

bool

LastChild

Gets the last child node of this node.

public T LastChild
   {
      get
      {
         var child = this.Children[this.Children.Count - 1];
         return (T)child;
      }
   }

Property Value

T

Methods

Accept(DocumentVisitor)

Accepts the visitor of the node.

public override void Accept(DocumentVisitor visitor)
   {
      visitor.Visit(this);
   }
This reformatted code follows standard C# conventions, including proper indentation and spacing.

Parameters

visitor DocumentVisitor

The object of a class derived from the Aspose.Note.DocumentVisitor.

AppendChildFirst(T1)

Adds the node to the front of the list of child nodes for this node.

public override T AppendChildFirst<T1>(T1 newChild) where T1 : T
   {
   }

Parameters

newChild T1

The node to add.

Returns

T1

The added node.

Type Parameters

T1

The exact type of appended node.

AppendChildLast(T1)

Adds the node to the end of the list of child nodes for this node.

public virtual T AppendChildLast<T1>(T1 newChild) where T1 : T
    {
    }

Parameters

newChild T1

The node to add.

Returns

T1

The added node.

Type Parameters

T1

The exact type of appended node.

GetChildNodes(NodeType)

Get all child nodes by node type.

[Obsolete("Use GetChildNodes<t>() method instead.")]
    public override List<Node> GetChildNodes(NodeType type)
    {
    }

Parameters

type NodeType

The node type.

Returns

List < INode >

A list of child nodes.

GetChildNodes()

Get all child nodes by the node type.

public override List<t1> GetChildNodes<t1>() where T1 : class, INode
{
    var result = new List<t1>();
    foreach (var node in _nodes)
    {
        if (node is t1 child && child.IsDescendantOf(this))
            result.Add(child);
    }
    return result;
}

Returns

List

A list of child nodes.

Type Parameters

T1

The type of elements in the returned list.

Examples

Shows how to get an image from a document.

string dataDir = RunExamples.GetDataDir_Images();
   Document oneFile = new Document(dataDir + "Aspose.one");
   IList<aspose.note.Image> nodes = oneFile.GetChildNodes<aspose.note.Image>();
   foreach (Aspose.Note.Image image in nodes)
   {
       using (MemoryStream stream = new MemoryStream(image.Bytes))
       {
           using (Bitmap bitmap = new Bitmap(stream))
           {
               bitmap.Save(String.Format(dataDir + "{0}", Path.GetFileName(image.FileName)));
           }
       }
   }

Shows how to get image’s meta information.

string dataDir = RunExamples.GetDataDir_Images();
   Document oneFile = new Document(dataDir + "Aspose.one");
   IList<aspose.note.Image> images = oneFile.GetChildNodes<aspose.note.Image>();
   foreach (Aspose.Note.Image image in images)
   {
      Console.WriteLine("Width: {0}", image.Width);
      Console.WriteLine("Height: {0}", image.Height);
      Console.WriteLine("OriginalWidth: {0}", image.OriginalWidth);
      Console.WriteLine("OriginalHeight: {0}", image.OriginalHeight);
      Console.WriteLine("FileName: {0}", image.FileName);
      Console.WriteLine("LastModifiedTime: {0}", image.LastModifiedTime);
      Console.WriteLine();
   }

GetEnumerator()

Returns an enumerator that iterates through child nodes of the Aspose.Note.CompositeNode`1.

public IEnumerator<T> GetEnumerator()
   {
   }

Returns

IEnumerator

A IEnumerator1 for the Aspose.Note.CompositeNode1.

InsertChild(int, T1)

Inserts the node to the specified position in the list of child nodes for this node.

public override T InsertChild<T1>(int index, T1 newChild)
        where T1 : T
    {
    }

Parameters

i int

Position to insert

newChild T1

The node to insert.

Returns

T1

The added node.

Type Parameters

T1

The exact type of inserted node.

InsertChildrenRange(int, IEnumerable)

Inserts the node’s sequence starting from specified position in the list of child nodes for this node.

public void InsertChildrenRange(int i, IEnumerable<t> newChildren)
   {
   }

Parameters

i int

Position to insert

newChildren IEnumerable

The sequence of nodes to be inserted.

InsertChildrenRange(int, params T[])

Inserts the node’s sequence starting from specified position in the list of child nodes for this node.

public void InsertChildrenRange(int i, params T[] newChildren)
{
}

Parameters

i int

Position to insert

newChildren T[]

The sequence of nodes to be inserted.

RemoveChild(T1)

Removes the child node.

public T RemoveChild<T>(T oldChild) where T : class
   {
   }

Parameters

oldChild T1

The node to remove.

Returns

T1

The removed node.

Type Parameters

T1

The exact type of removed node.

 English