A .NET library to select items from a node tree based on a CSS selector. The default implementation is based on HTMLAgilityPack and selects from HTML documents. There over 140 unit tests - see below for more information. The tests are based on the jQuery selector engine tests.
Fizzler supports .NET 2.0, 3.0, 3.5 and Mono.
Contributions are welcome in forms of:
- Increased selector support
- Implementation over an HTML-like hierarchical document model
- Re-factorings
- Improved tests
// 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 = html.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");View them here (Fizzler.Tests):
With_Non_Existant_ID_DescendantWith_Non_Existant_ID_AncestorWith_Existing_ID_DescendantWith_ElementWith_ElementStar_Prefix_With_DigitStar_NthChildStarSingle_Tag_Name_Matching_Multiple_ElementsSingle_Tag_NameSingleParent_Class_SelectorOnly_ChildNthChild_No_PrefixNot_A_Child_IDNo_Prefix_With_DigitLast_ChildFirst_ChildEmptyElement_Prefix_With_DigitElement_NthChildElement_Attr_Space_Separated_With_Double_QuotesElement_Attr_Space_SeparatedElement_Attr_Hyphen_Separated_With_Double_QuotesElement_Attr_Hyphen_SeparatedElement_Attr_ExistsElement_Attr_ExistsElement_Attr_Equals_With_Double_QuotesElement_Attr_EqualsDescendantCommaSupport_With_Pre_Post_Pended_SpaceCommaSupport_With_Pre_Pended_SpaceCommaSupport_With_Post_Pended_SpaceCommaSupport_With_No_SpaceComma_Child_And_AdjacentChild_With_SpacesChild_With_Pre_SpaceChild_With_Pre_And_Post_SpaceChild_With_Post_SpaceChild_With_No_SpaceChild_With_ClassChild_No_SpacesChild_IDChainedBasic_SelectorBasic_Positive_Precedence_With_Same_TagsBasic_Positive_Precedence_Two_TagsBasic_Positive_Precedence_Three_TagsBasic_Negative_PrecedenceBasicAll_GrandChildrenAll_Descendants_Of_IDAll_Children_of_ID_with_no_childrenAll_Children_Of_IDAll_ChildrenAdjacent_With_Pre_SpaceAdjacent_With_Pre_And_Post_SpaceAdjacent_With_Post_SpaceAdjacent_With_No_SpaceAdj_SpacesAdj_No_Spaces