views:

68

answers:

2

I've tried to set InnerText using the following, but I'm not allowed to set the InnerText property:

node.InnerText = node.InnerText.Remove(100) + ".."; 

The reason for this is that I only want to remove text, not actual elements:

<div>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit.
    <img src="" />
</div>
+1  A: 

Try using replace instead.

node.InnerText = node.InnerText.Replace("100" + "..", "");

This should replace the text 100.. with a null string.

Michael Eakins
The problem is that the InnerText property is read-only.
Andreas
A: 

I have just run into the same problem myself. Although the documentation says get or set it clearly is read-only. But inner text applies to EVERYTHING between the tags. So if you have hundred of children ALL of their text including actual tags will be there. I think to do what you and I are wanting we need to use the Text property. Get the actual tag and use the Text property.

So perhaps

HtmlTextNode.Text = "";

Please note that you can only set the text if it is of type HtmlTextNode.

or i think you might get a better result if you just remove the tag and keep the grandchildren.

HtmlNode.Parent.Remove(textTagYouWantRemoved, true);
uriDium