1
votes

I have a stylesheet stored as a string which I'm trying to add to a parsed HtmlDocument using the Html Agility Pack. I can't set the InnerText of a style node because it has no setter. What's the best way of doing this?

1
Did you try adding a whole style node? - Oded
new HtmlNode(...) and append it? Not sure it will work, but worth a shot. - Oded
But the InnerText property has no setter so I can't set the content. - Echilon

1 Answers

2
votes

Untested, but should give you the idea:

// doc is the HtmlDocument
var style = doc.CreateElement("style");
var text = doc.CreateTextNode("some CSS here");
style.AppendChild(text);
doc.DocumentNode.AppendChild(style); // or, AppendChild to any node