Nevron .NET Vision
Framework / System Layer / Document Object Model / Nodes

In This Topic
    Nodes
    In This Topic
    Many applications require to hierarchically organize their documents or other internally maintained object structures. In fact the hierarchical organization of object structures is a core concept in the building of every type of application. In this aspect each object in a hierarchy can be treated as a tree node (or simply node) in the object structure tree. In the Nevron DOM the basic abstraction of node is represented by the INNode interface.
     Types of Nodes

    In general there are two types of nodes:

    • Leaf  - a node without any child nodes
    • Branch - a node with one or more child nodes

    Common for all types of nodes is that you can obtain the immediate node parent as well as the root node (the topmost node in the hierarchy). For example:

    C#
    Copy Code
    // obtain the node parent in the scene
    INNode parent = node.ParentNode;
    // obtain the scene root
    INNode root = node.RootNode;
    
    Visual Basic
    Copy Code
    ' obtain the node parent in the scene
    Dim parent as INNode = node.ParentNode
    ' obtain the scene root
    Dim root as INNode = node.RootNode
    
     Branch Nodes

    Branch nodes can also be classified as follows:

    • Branches with predefined children - these are branch nodes whose children are predefined for the purpose of the specific objects structure. In Nevron DOM this type of branch nodes is represented by the INNodeContainer interface (derived from INNode ). For each node container you can execute the following code:
      C#
      Copy Code
      // get the container child nodes
      NNodeList children = container.Children(null);
      // get the child at some index
      INNode child = container.GetChildAt(0);
      // get the container descendant nodes
      NNodeList descendants = container.Descendants(null);
      
      Visual Basic
      Copy Code
      ' get the container child nodes
      Dim children As NNodeList = container.Children(Nothing)
      ' get the child at some index
      Dim child As INNode = container.GetChildAt(0)
      ' get the container descendant nodes
      Dim descendants As NNodeList = container.Descendants(Nothing, -1)
      
    • Branches with user defined children - these are branch nodes to which you can insert and remove children. In Nevron DOM this type of branch nodes is represented by the INNodeComposite interface. INNodeComposite (derived from INNodeContainer ). For each composite node you can execute the following code:
      C#
      Copy Code
      // add a child node
      composite.AddChild(node1);
      // insert a child node
      composite.InsertChild(0, node2);
      // remove a child node
      composite.RemoveChild(node1);
      // remove a child at some index
      composite.RemoveChildAt(0);
      
      Visual Basic
      Copy Code
      ' add a child node
      composite.AddChild(node1)
      ' insert a child node
      composite.InsertChild(0, node2)
      ' remove a child node
      composite.RemoveChild(node1)
      ' remove a child at some index
      composite.RemoveChildAt(0)
      
     Node Subtree Enumeration

    It is also often required to enumerate the nodes, which reside in the sub tree of a particular node container. The Nevron DOM provides two types of node tree enumerators - forward and reversed. They both support the following tree traversal orders:

    • Breadth First - visits the nodes by levels
    • Depth First Post Order - visits the children and then visits the parent
    • Depth First Pre Order - visits the parent and then visits the children
    C#
    Copy Code
    // forward enumeration 
    NNodeTreeEnumerator en = new NNodeTreeEnumerator(nodeContainer, null, -1, TreeTraversalOrder.DepthFirstPreOrder); 
    while (en.MoveNext())
    { 
        INNode cur = (INNode)en.Current;
    } 
    
    // reverse enumeration 
    NReverseNodeTreeEnumerator ren = new NReverseNodeTreeEnumerator(nodeContainer, null, -1, TreeTraversalOrder.DepthFirstPreOrder);
    while (ren.MoveNext())
    {
        INNode cur = (INNode)en.Current;
    }
    
    Visual Basic
    Copy Code
    ' forward enumeration
    Dim en As New NNodeTreeEnumerator(nodeContainer, Nothing, -1, TreeTraversalOrder.DepthFirstPreOrder)
    While en.MoveNext()
        Dim cur As INNode = en.Current
    End While
    
    ' reverse enumeration
    Dim ren As New NReverseNodeTreeEnumerator(nodeContainer, Nothing, -1, TreeTraversalOrder.DepthFirstPreOrder)
    While ren.MoveNext()
        Dim cur As INNode = ren.Current
    End While
    
     Implementation
    The Nevron DOM provides an implementation of the INNodeComposite interface, which is represented by the NNodeCompositeImpl  class.
    See Also