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. At this time, the library is BETA quality.
Fizzler supports .NET 2.0, 3.0, 3.5 and Mono.
Contributions are welcome in forms of:
- Re-factoring
- Improved tests
- Increased selector support
Examples
We have this HTML in a string variable called html:
<html>
<head></head>
<body><div><p class="content">Fizzler</p><p>CSS Selector Engine</p></div></body>
</html>// load the document using HTMLAgilityPack as normal
var htmlDocument = new HtmlDocument();
htmlDocument.LoadHtml(html);
// Fizzler for HtmlAgilityPack is implemented as an QuerySelectorAll extension method to HtmlNode
var documentNode = htmlDocument.DocumentNode;
documentNode.QuerySelectorAll(".content"); // returns [<p class="content">Fizzler</p>]
documentNode.QuerySelectorAll("p"); // returns [<p class="content">Fizzler</p><p>CSS Selector Engine</p>]
documentNode.QuerySelectorAll("body>p") // returns empty collection
documentNode.QuerySelectorAll("body p") // returns [<p class="content">Fizzler</p><p>CSS Selector Engine</p>]
documentNode.QuerySelectorAll("p:first-child") // returns [<p class="content">Fizzler</p>]Test Overview
View them here:
- With_Non_Existant_ID_Descendant
- With_Non_Existant_ID_Ancestor
- With_Existing_ID_Descendant
- With_Element
- With_Element
- Star_Prefix_With_Digit
- Star_NthChild
- Star
- Single_Tag_Name_Matching_Multiple_Elements
- Single_Tag_Name
- Single
- Parent_Class_Selector
- Only_Child
- NthChild_No_Prefix
- Not_A_Child_ID
- No_Prefix_With_Digit
- Last_Child
- First_Child
- Empty
- Element_Prefix_With_Digit
- Element_NthChild
- Element_Attr_Space_Separated_With_Double_Quotes
- Element_Attr_Space_Separated
- Element_Attr_Hyphen_Separated_With_Double_Quotes
- Element_Attr_Hyphen_Separated
- Element_Attr_Exists
- Element_Attr_Exists
- Element_Attr_Equals_With_Double_Quotes
- Element_Attr_Equals
- Descendant
- CommaSupport_With_Pre_Post_Pended_Space
- CommaSupport_With_Pre_Pended_Space
- CommaSupport_With_Post_Pended_Space
- CommaSupport_With_No_Space
- Comma_Child_And_Adjacent
- Child_With_Spaces
- Child_With_Pre_Space
- Child_With_Pre_And_Post_Space
- Child_With_Post_Space
- Child_With_No_Space
- Child_With_Class
- Child_No_Spaces
- Child_ID
- Chained
- Basic_Selector
- Basic_Positive_Precedence_With_Same_Tags
- Basic_Positive_Precedence_Two_Tags
- Basic_Positive_Precedence_Three_Tags
- Basic_Negative_Precedence
- Basic
- All_GrandChildren
- All_Descendants_Of_ID
- All_Children_of_ID_with_no_children
- All_Children_Of_ID
- All_Children
- Adjacent_With_Pre_Space
- Adjacent_With_Pre_And_Post_Space
- Adjacent_With_Post_Space
- Adjacent_With_No_Space
- Adj_Spaces
- Adj_No_Spaces