从html中删除节点

时间:2012-05-31 10:32:08

标签: c# asp.net-mvc-3

我正在使用HtmlAgilityPack解析html文档,现在当我替换或删除任何子元素时:

        string TargetPath = Path.Combine(Server.MapPath("/Views/SaveChange"),
        User.Identity.Name + "Test.cshtml");

        HtmlDocument ndoc = new HtmlDocument();
        ndoc.Load(TargetPath);

        ndoc.DocumentNode.RemoveChild(ndoc.GetElementbyId("id"), false);
        ndoc.save(TargetPath);

执行此操作后,当我打开Test.cshtml文件时,所有结束标记变为未关闭​​,如

before removing child => <img .. />
after removing child => <img ..>

任何人都可以告诉我这里的问题吗?

0 个答案:

没有答案