删除样式标签及其内容 [英] remove style tag and its contents

查看:79
本文介绍了删除样式标签及其内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用c#删除html文件中的样式标签及其内容?

需要诸如LINQ等先进技术的解决方案格式正确(它可能还需要调整,因为我是从头顶输入的):

 XElement标签= XElement.Parse("  font-height:10px; " ));
XAttribute style = tag.Attribute(" ).Value;
如果(样式!= )
{
    字符串 newTagString = tag.ToString().Replace(字符串 .Format(  style = \"{0} \"",style.ToString()), );
    标签= XElement.Parse(newTagString);
} 


How can i remove style tag and its contents in html file using c#?

Need a solution in advanced technology like LINQ etc

解决方案

There are probably better ways, and indeed, this method assumes there''s no whitespace, and that the html is properly formed (it may also need tweaking because I typed it off the top of my head):

XElement tag = XElement.Parse("<span style="font-height:10px;">some text</span>");
XAttribute style = tag.Attribute("style").Value;
if (style != null)
{
    string newTagString = tag.ToString().Replace(string.Format("style=\"{0}\"", style.ToString()), "");
    tag = XElement.Parse(newTagString);
}


这篇关于删除样式标签及其内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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