I need to be able to simply specify elements from html in my C# application. I would just use Linq to Sql but this needs to be configurable/serializable to a string. I could of course use XPath but something like Sizzle at this point is just so much more natural for most people.
Anyone know if a sizzle selectors implementation exists in .Net?
Sizzle is a JavaScript selector library that offers powerful ways to select elements. You can select based off text contained (or not contained) within elements, the existence of child elements inside a parent, or if those elements do not exist.
Sizzle. js is a JavaScript library that implements a "CSS selector engine designed to be easily dropped in to a host library." jQuery uses it internally for its CSS selection needs. If you wanted a CSS engine and had no need for all the other JavaScript benefits of jQuery, you could use Sizzle.
If dealing with more than two selectors in a row then your last selectors are always executed first. For example, jQuery will first find all the elements with class “. list” and then it will select all the elements with the id “second”.
Two selectors: visible and: hidden are also available in JQuery.
Yepp, Fizzler. It's built upon HtmlAgilityPack and works very well, even though the authors says it's beta. We use it in production on a major project. Samples from the documentation:
// Load the document using HTMLAgilityPack as normal
var html = new HtmlDocument();
html.LoadHtml(@"
<html>
<head></head>
<body>
<div>
<p class='content'>Fizzler</p>
<p>CSS Selector Engine</p></div>
</body>
</html>");
// Fizzler for HtmlAgilityPack is implemented as the
// QuerySelectorAll extension method on HtmlNode
var document = htmlDocument.DocumentNode;
// yields: [<p class="content">Fizzler</p>]
document.QuerySelectorAll(".content");
// yields: [<p class="content">Fizzler</p>,<p>CSS Selector Engine</p>]
document.QuerySelectorAll("p");
// yields empty sequence
document.QuerySelectorAll("body>p");
// yields [<p class="content">Fizzler</p>,<p>CSS Selector Engine</p>]
document.QuerySelectorAll("body p");
// yields [<p class="content">Fizzler</p>]
document.QuerySelectorAll("p:first-child");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With