6
我正在使用HTML Agility Pack来操作和编辑HTML文档。我想改变在该领域的文本,如本:使用HTML Agility Pack替换HTML div InnerText标记
<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是一个只读字段,虽然它是写在文档中的“获取或设置”。有没有其他方法可以做到这一点?
工程就像一个魅力!非常感谢... – Vivek 2012-02-02 04:55:49