views:

288

answers:

4

Hello,

I'm wondering if there's a jQuery-like css selector that can be used in C#.

Currently, I'm parsing some html strings using regex and thought it would be much nicer to have something like the css selector in jQuery to match my desired elements.

Let me know if I'm not too clear on the subject.

Thanks

+2  A: 

For XML you might use XPath...

Frank Schwieterman
Oh yea, I forgot to mention that. I wanted something like the css selector for it's simplicity and clarity.
Dave
+1  A: 

I'm not entirely clear as to what you're trying to achieve, but if you have a HTML document that you're trying to extract data from, I'd recommend loading it with a parser, and then it becomes fairly trivial to query the object to pull desired elements.

The parser I linked above allows for use of XPath queries, which sounds like what you are looking for.

Let me know if I've misunderstood.

patjbs
May I know what parser you are refering to?I just want something like Doc.select("div.foo") to return all the elements that is a div and have class foo.
Dave
I added a link to the text, which points to a SO question about parsing HTML. In particular, the HTML Agility pack parser I've used in the past to load HTML docs and query against them with great success.
patjbs
A: 

Not quite jQuery like, but this may help: http://www.codeplex.com/htmlagilitypack

Daniel
yes... I just looked over the html agility pack few days ago. But, it still uses XPath for matching. It's not that I don't like XPath. But, the cleanness of the css selector syntax is much better imo.
Dave
LINQ-to-Objects is probably what I'd use. But right - not as clean as selectors.
Daniel
+3  A: 

Fizzler is exactly what you're looking for...

Andy S