【发布时间】:2021-06-13 11:18:56
【问题描述】:
我正在尝试删除 C# 中的某些 html 标签,如下所示:
<div>
<blockquote style="font-size: 30px" width="300px">
For 50 years, WWF has been protecting the future of nature. The world's leading conservation organization, WWF works in 100 countries and is supported by 1.2 million members in the United States and close to 5 million globally.
</blockquote>
</div>
作为结果
<div>For 50 years, WWF has been protecting the future of nature. The world's leading conservation organization, WWF works in 100 countries and is supported by 1.2 million members in the United States and close to 5 million globally.</div>
到目前为止,我正在尝试使用正则表达式。 (<.+?)\s+style\s*=\s*([""']).*?\2(.*?>) 但这仅用于删除样式,但我不确定如何才能达到我想要的结果。
谢谢!
【问题讨论】:
-
你的标准是什么?在这种情况下,“组织,...”可能因内容而异,那么如何剪切文本?
-
问候@SeaBean 我更新了这个问题。很抱歉造成混乱
-
但是我需要有一种方法来删除某个标签的html标签,例如,它是
<blockquote> -
使用 XML 解析器。将 text-node 上移一级,移除 blockquote 节点,保存,完成。