Html Agility Pack - Remove element, but not innerHtml

后端 未结 10 2102
予麋鹿
予麋鹿 2021-01-06 11:46

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

HtmlDocument html = new HtmlDocument();

html.Load(Server.MapPath(@\"~\\Site\\themes\\default         


        
10条回答
  •  旧巷少年郎
    2021-01-06 12:01

    How about this?

    var removedNodes = document.SelectNodes("//removeme");
    if(removedNodes != null)
        foreach(var rn in removedNodes){
            HtmlTextNode innernodes =document.CreateTextNode(rn.InnerHtml);
            rn.ParnetNode.ReplaceChild(innernodes, rn);
        }
    

提交回复
热议问题