find and remove css references in html head, C#

jerk721

New Member
I have created a service to join, minify and compress css-references on a CMS system. Example:Before :\[code\]<link href="http://stackoverflow.com/Files/css1.css" rel="stylesheet" type="text/css"/><link href="http://stackoverflow.com/Files/css2.css" rel="stylesheet" type="text/css"/><link href="http://stackoverflow.com/Files/css3.css" rel="stylesheet" type="text/css" media="all"/>\[/code\]Now you can write:\[code\]<link href="http://stackoverflow.com/min.ashx?files=/Files/css1.css,/Files/css2.css,/Files/css3.css" rel="stylesheet" type="text/css" />\[/code\]My next task is to take all references in head section AUTOMATICALLY and replace them by one single line, as seen in the example.I should only replace those that falls with in these rules:
  • Href starts with '/Files/', to avoid trying to load externals externals
  • Only the ones with attribute media or with a media="all" should be included, as the resulting css-file will only have one setting.
I have acces to the raw html of the page, but is stuck on sucsfully locating the references, not knowing if I should parse to xml or use regex or such..can anyone point me in the right direction?
 
Back
Top