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?
Asked
Active
Viewed 754 times
1

Echilon
- 10,064
- 33
- 131
- 217
-
Did you try adding a whole style node? – Oded Dec 29 '12 at 16:10
-
`new HtmlNode(...)` and append it? Not sure it will work, but worth a shot. – Oded Dec 29 '12 at 16:15
-
1But the `InnerText` property has no setter so I can't set the content. – Echilon Dec 29 '12 at 16:20
1 Answers
2
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

Oded
- 489,969
- 99
- 883
- 1,009