Click here to Skip to main content
15,922,894 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can i remove style tag and its contents in html file using c#?

Need a solution in advanced technology like LINQ etc
Posted

1 solution

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

C#
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);
}
 
Share this answer
 
v3
Comments
srinivasan_indian 15-Dec-11 8:55am    
Need a full code
#realJSOP 15-Dec-11 8:56am    
You're a programmer, do it yourself. I pointed you in the right direction for god's sake.
srinivasan_indian 15-Dec-11 9:37am    
Where we place a file path to be remove?
fjdiewornncalwe 15-Dec-11 10:28am    
+5. It's a lot more than I would have given as I suspect this to be a homework question
srinivasan_indian 15-Dec-11 10:59am    
I removed specific tag in html file using Html agility pack.

Bu i want to use some advanced technologies like LINQ or some thing else to remove specific tag in html file in c#

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900