设置的InnerText与HtmlAgilityPack [英] Set InnerText with HtmlAgilityPack

查看:235
本文介绍了设置的InnerText与HtmlAgilityPack的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着用下面的设置的InnerText,但我不允许设置InnerText属性:

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



这样做的原因是,我只希望删除文本,而不是实际的元素:



 < D​​IV> 
Lorem存有悲坐阿梅德,consectetur adipiscing ELIT。
< IMG SRC =/>
< / DIV>


解决方案

我刚刚碰到同样的问题我自己。虽然文件说,获取或明确将其设置为只读。但内部文本适用于标签之间的一切。所以,如果你有孩子几百他们所有的文本包括实际标签将在那里。我想,做你和我想我们需要使用Text属性。获取实际的标签和使用Text属性。



因此​​,也许

  HtmlTextNode.Text =; 

请注意,您可以只设置文本,如果它的类型是HtmlTextNode的。



或我想你可能会得到一个更好的结果,如果你只是删除标记,并保持孙子。

  HtmlNode.Parent.Remove(textTagYouWantRemoved,真); 


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>

解决方案

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);

这篇关于设置的InnerText与HtmlAgilityPack的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆