Search code examples
c#.netcssdotless

Is there a CSS object model or CSS querying api for .net?


Is there a library out there that will allow me to write the following kind of code, which parses CSS and returns a queryable object model

string input = "p, span { font-family: arial; }";
var cssRules = new Parser().Parse(input);
var rule = cssRules.Find(new Selector("p")).First();

Assert.That(rule.Attribute("font-family").Value, Is.Equal.To("arial"));

I've taken a look at dotless, downloaded their code and examined some of the relevant unit tests and fixtures. It looks promising but I can't quite work out how to use it to parse and query plain CSS.


Solution

  • The closest I know is CssParser from jsonfx.net:

    http://css-parser.googlecode.com/svn/trunk/CssParser/

    You can parse any css and browse through selectors afterwards using StyleSheet property of CssParser