Q:

From html tag to xml attribute

I'm using C#.
I have the following html text:
< strong>Testing< /strong>; (without the space before start tag, end tag).
I'm trying to insert this html text to attribute of my html element as follow:
<MyElement myAttribute=\"&lt;strong&gt;Testing&lt;/strong&gt;\"/>

How can i "convert" from html format to xml attribute format?

A:

You can simply use https://msdn.microsoft.com/en-us/library/73z22y6h(v=vs.110).aspx
I.e
string encodeValue = HttpUtility.HtmlEncode("<strong>Testing</strong>");

And then you can use encodeValue to insert into your xml attribute.

