2

I want to format my html through C#. Here my example code.

<div dir="ltr"><div class="gmail_quote"><strong><span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">CA IQVIA EM Event Speaker info</span></strong></div></div>

I want to output like this :

`<div dir="ltr">
    <div class="gmail_quote">
       <strong>
        <span style="font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">
           CA IQVIA EM Event Speaker info
         </span>
        </strong>
    </div>
 </div>`

How Should I achieve this? Thanks in advance.

2
  • 1
    Please show what you have tried. Stackoverflow is not a free code writing service or a "how to" tutorial service. The objective here is for others to help you fix your code when it doesn't work as expected
    – SwapNeil
    Aug 16, 2018 at 9:56
  • Possible duplicate: stackoverflow.com/questions/5680251/… Aug 16, 2018 at 10:01

1 Answer 1

3

This is what you need.

var input = "<div dir=\"ltr\"><div class=\"gmail_quote\"><strong><span style=\"font-family:&quot;Arial&quot;,&quot;sans-serif&quot;\">CA IQVIA EM Event Speaker info</span></strong></div></div>";

try
{
  var formatted = System.Xml.Linq.XElement.Parse(input).ToString();
}
catch
{
  // Your input is not a valid xml fragment.
}
4

Not the answer you're looking for? Browse other questions tagged or ask your own question.