How To Delete A Html Tag Alone But Not Inner Html Or Children Tag Using Htmlagilitypack?
I need to delete an html tag say in the following code,
Solution 1:
var tbody = document.DocumentNode.SelectSingleNode("//tbody");
tbody.ParentNode.RemoveChild(tbody, keepGrandChildren: true);
OUTPUT:
<table><tr><tdvalign="bottom"></td><tdvalign="bottom"></td><tdvalign="bottom"></td></tr><tr><td></td><td></td><td></td></tr></table>
Solution 2:
The inner html is an integral part of the tag, that's why the inner html is also getting deleted.
What you need to do is replace the <tbody>
tag by the inner html of <tbody>
, in your case, something like this (i did not check if this code works, but you get the idea):
document.DocumentNode.SelectSingleNode("//table").innerHTML = document.DocumentNode.SelectSingleNode("//tbody").innerHTML;
Solution 3:
If you give your tags an id, you should be able to access the element by id. This will make it super easy to delete.
Post a Comment for "How To Delete A Html Tag Alone But Not Inner Html Or Children Tag Using Htmlagilitypack?"