插入元素代码后的HtmlNode保持不变

时间:2013-11-28 01:46:20

标签: c# html data-binding nodes

我已经使用HtmlNode绑定了TreeNode 使用TreeNode.Tag 当我在treeView中更改某些内容时,我会动态更改HtmlDocument(HtmlAgilityPack)

所以继承了一个代码,它在同一个地方向treeview和htmldocument追加一个元素:

      //add element 
        var selected = Hiererchy.SelectedNode;
        if (selected != null && selected.Tag != null)
        {

            HtmlNode htmlSelected = selected.Tag as HtmlNode;
            if (htmlSelected.NodeType == HtmlNodeType.Element)
            {
                HtmlNode htmlNew = HtmlNode.CreateNode("<div></div>");
                htmlSelected.ChildNodes.Add(htmlNew);
                TreeNode newTree = new TreeNode();
                newTree.Tag = htmlNew;
                newTree.Name = htmlNew.Name;
                newTree.Text = formatAsLabel ( "<" + htmlNew.Name + ">" );
                selected.Nodes.Add(newTree);
            }
            else
            {
                MessageBox.Show("can only add node to element");
            }
        }
        refresh();

并且新元素出现在treeWiev上,但是,当我调用document.DocumentNode.InnerHtml;时,代码保持完全相同,就像调用上面的代码之前一样。那是为什么?

0 个答案:

没有答案