Exemplo n.º 1
0
        void UpdateNode(TreeNode tn, NsNode node)
        {
            tn.Tag = node;
            tn.Text = node.Label;
            TreeNode atr;
            //add or update attribute nodes
            foreach (IAttribute attr in node.Attributes)
            {
                atr = GetChildNode(attr, tn);
                if (atr != null) //attribute found, update value
                    UpdateAttribute(atr, attr);

                else //attribute not found, add new
                {
                    atr = new TreeNode();
                    UpdateAttribute(atr, attr);
                    tn.Nodes.Add(atr);
                }
            }
            //add or update subnodes
            foreach (NsNode n in node)
            {
                atr = GetChildNode(n, tn);
                if (atr != null)
                    UpdateNode(atr, n);
                else
                {
                    atr = new TreeNode();
                    UpdateNode(atr, n);
                    tn.Nodes.Add(atr);
                }
            }
            //remove deleted nodes
            foreach (TreeNode t in tn.Nodes)
            {
                if (!node.HasChild(t.Tag))
                    t.Remove();
            }
        }