HTML敏捷性包 - 删除元素,但不能的innerHTML [英] Html Agility Pack - Remove element, but not innerHtml

查看:248
本文介绍了HTML敏捷性包 - 删除元素,但不能的innerHTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以很容易地只是note.Remove()LIK这个删除的元素:

 的HTMLDocument HTML =新的HTMLDocument() ; 

html.Load(使用Server.Mappath(@〜\Site\themes\default\index.cshtml));

的foreach(在html.DocumentNode.SelectNodes(VAR项目// removeMe))
{
item.Remove();
}



但是,删除的innerHTML为好。
如果什么,我只是想删除标记,并保持的innerHTML



?例如:

 < UL> 
< removeMe>
<立GT;
< A HREF =#>保持ME< / A>
< /李>
< / removeMe>
< / UL>



任何帮助,将不胜感激:)


解决方案

  HtmlAgilityPack.HtmlDocument DOC =新HtmlAgilityPack.HtmlDocument(); 
doc.LoadHtml(HTML);

VAR节点= doc.DocumentNode.SelectSingleNode(// removeme);
node.ParentNode.RemoveChild(节点,真正的);


I can easily remove the element just by note.Remove() lik this:

HtmlDocument html = new HtmlDocument();

html.Load(Server.MapPath(@"~\Site\themes\default\index.cshtml"));

foreach (var item in html.DocumentNode.SelectNodes("//removeMe"))
{
    item.Remove();
}

But that removes the innerHtml as well. What if i only want to remove the tag, and keep the innerHtml?

Example:

<ul>
    <removeMe>
        <li>
            <a href="#">Keep me</a>
        </li>
    </removeMe>
</ul>

Any help would be appreciated :)

解决方案

HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(html);

var node = doc.DocumentNode.SelectSingleNode("//removeme");
node.ParentNode.RemoveChild(node, true);

这篇关于HTML敏捷性包 - 删除元素,但不能的innerHTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆