Hi,
I have the following HTML, storing in a string in C# code (string html = "below html";).
There are five tables in HTML and I want to remove table tag from string where table id = 'Location2'. Please advise
Code
NOTIFICATION
Column-1
Column-1 Value
Column-2
Column-2 Value
Location-1
Name:
Location Name
AddrLine:
Location Address
Location-2
Name:
Location Name
AddrLine:
Location Address
Summary
Distance (Miles):
150
Distance (Meter):
200

Amit MohantyRank #112 · 20K reputationPosted Nov 8, 2022, 4:26 AM EST
Try this
using HtmlAgilityPack; string text = "your html text"; HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(text); var nodes = doc.DocumentNode.SelectNodes("//table[@id='Location2']"); foreach (HtmlNode node in nodes) { node.Remove(); } string result = doc.DocumentNode.InnerHtml;Brahma Prakash ShuklaRank #633 · 3.8K reputationPosted Nov 8, 2022, 12:21 AM EST
Put that table inside the div and use js code to remove table tag from the string then pass it to the server side in c# code.
var html = $('#datatable').html(); var tags = ["", ""]; for (var i = 0; i -1) { html = html.replace(tags[i], ""); } } alert(html);Muhammad Imran AnsariRank #326 · 7.6K reputationPosted Nov 8, 2022, 4:00 AM EST
Thanks Brahma for reply.
I want to achieve this in C# code. HTML is in a tring veriable and want to remove table (where id = 'Location2') from string.