【问题标题】:Adding a Stylesheet with the HAP使用 HAP 添加样式表
【发布时间】:2012-12-30 00:25:11
【问题描述】:

我有一个存储为字符串的样式表,我正在尝试使用 Html Agility Pack 添加到已解析的 HtmlDocument 中。我无法设置 style 节点的 InnerText,因为它没有设置器。这样做的最佳方法是什么?

【问题讨论】:

  • 您是否尝试添加一个完整的样式节点?
  • new HtmlNode(...) 并附加它?不确定它会起作用,但值得一试。
  • 但是InnerText 属性没有设置器,所以我无法设置内容。

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


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-08
    • 2021-02-10
    • 2012-04-11
    • 2015-08-05
    • 1970-01-01
    • 2014-06-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多