I need to process html and I need it to be valid from XHTML perspective. For instance self-closing tags, such as <br>
and <hr>
in XHTML should be <br />
and <hr />
respectively.
So to take care of this issue, I converted my HTML to text and replace all <br>
tags with <br />
and <hr>
- with <hr />
.
Now the issue is that some <hr>
tags have properties. For example:
<hr width="100%" size="3" align="center" style="color: rgb(153,153,153);">
In his case the replacement becomes more complicated as I cannot simply use
str = str.Replace("<hr>","<hr/>")
Is there an easier way then writing a function that searches for every occurrence of "<hr"
and then looks for the following ">"
and replaces it with "/>"
?