I use the HTML Agility Pack to manage and edit an HTML document. I want to change the text in a field, for example:
<div id="Div1"><b>Some text here.</b><br></div>
I want to update the text inside this div:
<div id="Div1"><b>Some other text.</b><br></div>
I tried to do this using the following code, but it doesn't seem to work because the InnerText property is read-only.
HtmlTextNode hNode = null; hNode = hDoc.DocumentNode.SelectSingleNode("//div[@id='Div1']") as HtmlTextNode; hNode.InnerText = "Some other text."; hDoc.Save("C:\FileName.html");
What am I doing wrong here? As mentioned above, InnerText is a read-only field, although it is written in the documentation that it “receives or installs”. Is there an alternative method by which this can be done?
source share