HTMLAgilityPack: C# how to add strings with tags using CreateNode

c# html-agility-pack

Question

I'm trying to build HTML output with data that might contain HTML tags (simple ones, link or
).

If I add such a string to my HTML using CreateNode, some unwanted filtering happens. How can I fix this?

Example:

string myText = "<strong>Intro</strong><br />Some Explanation";
node.ParentNode.ReplaceChild(HtmlNode.CreateNode(myText, node);

In my resulting HTML, only the strong text is outputted, the rest is gone.

Popular Answer

Why don't you try using InnerHtml ?

string myText = "<strong>Intro</strong><br />Some Explanation";
node.ParentNode.InnerHtml = myText;



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why