c# - 使用 HAP 添加样式表

标签 c# .net html css html-agility-pack

我有一个存储为字符串的样式表,我试图使用 Html Agility Pack 将其添加到已解析的 HtmlDocument 中。我无法设置 style 节点的 InnerText,因为它没有 setter 。执行此操作的最佳方法是什么?

最佳答案

未经测试,但应该给你想法:

// 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

关于c# - 使用 HAP 添加样式表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14083457/

相关文章:

c# - 遍历 List<T> 时出现空引用异常

c# - 无法让 TextBlock 在 ListBox 内自动换行

c# - 我将如何编写这个遗传算法?

C# string to Decimal On All style or 文化

html - 两个div的高度基于主div的高度相等

c# - 在 ASP.NET MVC 中加密 Json 中发送的数据

c# - 删除#region

c# - 如何计算一组日期之间的间隔?

javascript - jQuery 自定义复选框 + 隐藏 html 复选框

html - 我如何让这个 div 到中心?