I have one 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.So, i want to remove both the tags...
can you help me to remove all <br>
tags in my html string...
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);
string html = ...;
string html = Regex.Replace(html, "<br>", "", RegexOptions.Singleline);