Reputation: 11592
I have an HTML string and I am using HtmlAgilityPack for parsing HTML string.
This is my html string:
<p class="Normal-P" style="direction: ltr; unicode-bidi: normal;"><span class="Normal-H">sample<br/></span> <span class="Normal-H">texting<br></span></p>
This HTML string has <br>
tag in two places. How can I remove both of them?
Upvotes: 3
Views: 3554
Reputation: 13033
string html = ...;
string html = Regex.Replace(html, "<br>", "", RegexOptions.Singleline);
Upvotes: 1
Reputation: 40516
It's as easy as:
HtmlDocument
<br />
tags using the "//br"
xpath expressionRemove()
methodDocumentNode.OuterHtml
propertyHere it is in code:
const string htmlFragment =
@"<p class=""Normal-P"" style=""direction: ltr; unicode-bidi: normal;"">" +
@"<span class=""Normal-H"">sample<br/></span>" +
@"<span class=""Normal-H"">texting<br></span></p> ";
var document = new HtmlAgilityPack.HtmlDocument();
document.LoadHtml(htmlFragment);
foreach (var brTag in document.DocumentNode.SelectNodes("//br"))
brTag.Remove();
Console.WriteLine(document.DocumentNode.OuterHtml);
Upvotes: 5