Nhóm :
Member
Tham gia:
16-06-2010
Bài viết:
43
Lần thăm:
308

C# - Replacing specific HTML tags using HtmlAgilityPack

Also it is generally a better idea to use an HTML parser like HtmlAgilityPack than trying to parse HTML using regular expressions. Here's how you could do it:

An example of what I want to do is replace any match of by in order to use a supported tag for text-alignment.

HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(html); foreach (var e in doc.DocumentNode.Descendants("div")) e.Name = "p"; doc.Save(Console.Out);


Result: