【发布时间】:2012-02-24 00:19:07
【问题描述】:
我正在使用 HTML Agility Pack 来操作和编辑 HTML 文档。我想更改字段中的文本,例如:
<div id="Div1"><b>Some text here.</b><br></div>
我希望将此 div 中的文本更新为:
<div id="Div1"><b>Some other text.</b><br></div>
我已尝试使用以下代码执行此操作,但它似乎不起作用,因为 InnerText 属性是只读的。
HtmlTextNode hNode = null;
hNode = hDoc.DocumentNode.SelectSingleNode("//div[@id='Div1']") as HtmlTextNode;
hNode.InnerText = "Some other text.";
hDoc.Save("C:\FileName.html");
我在这里做错了什么?如上所述,InnerText 是一个只读字段,尽管它写在它“获取或设置”的文档中。有没有其他方法可以做到这一点?
【问题讨论】:
标签: c# asp.net html-parsing html-agility-pack