Guest User

Untitled

a guest
Nov 22nd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. public void SetFonts()
  2. {
  3. string strHtml = "<span style="font-size: 10px; ">Hi This is just a section of html text.</span><span style="font-family: 'Verdana'; font-size: 10px; ">Please help</span><span>me add style attributes to span tags.Thank You</span>";
  4. HtmlDocument document = new HtmlDocument();
  5. document.LoadHtml(strHtml);
  6. SetFonts(document.DocumentNode);
  7. document.Save(Console.Out);
  8. }
  9.  
  10.  
  11. public void SetFonts(HtmlNode node)
  12. {
  13. foreach (var item in node.Elements("span"))
  14. {
  15. var style = item.GetAttributeValue("style", null);
  16. if (style != null)
  17. {
  18. if (!style.Contains("font-family"))
  19. {
  20. var newValue = style + "font-family: 'Verdana';";
  21. item.SetAttributeValue("style", newValue);
  22. }
  23. }
  24. SetFonts(item);
  25. }
  26. }
Add Comment
Please, Sign In to add comment