Permalink
Browse files

add support for .WithAttributeNamed().IgnoreCase().HavingValue(); upd…

…ate samples
  • Loading branch information...
1 parent 6fbff4b commit c59430ee91dfddc1a5d2ce17590c3badb7a1ce71 @handcraftsman handcraftsman committed Jul 16, 2010
View
@@ -5,11 +5,33 @@ A simple utility that lets you use LINQ syntax to query HTML.
const string html = "<html><head><TITLE>The Title</TITLE></head><body>Hello World</body></html>";
var parsed = HTMLParser.Parse(html);
+ const string html = @"
+<html>
+ <head>
+ <TITLE>The Title</TITLE>
+ </head>
+ <body bgcolor='#ffffff'>
+ <H1 id='hello' style='greeting'>Hello</H1>
+ <H2 id='world' style='greeting'>World</H2>
+ </body>
+</html>";
+
+ var parsed = HTMLParser.Parse(html);
+
+ parsed
+ .Head
+ .Content
+ .ShouldBeEqualTo("The Title");
+
+ parsed
+ .ChildTags
+ .Count()
+ .ShouldBeEqualTo(2); // head, body
+
parsed
.DescendantTags
- .OfType("title").IgnoreCase()
- .Any()
- .ShouldBeTrue();
+ .Count(x => x.Parent.TypeEqualsIgnoreCase("HTML"))
+ .ShouldBeEqualTo(2); // head, body
parsed
.DescendantTags
@@ -18,33 +40,41 @@ A simple utility that lets you use LINQ syntax to query HTML.
.ShouldBeFalse();
parsed
- .ChildTags
- .Count()
- .ShouldBeEqualTo(2); // head, body
-
+ .DescendantTags
+ .OfType("title").IgnoreCase()
+ .Any()
+ .ShouldBeTrue();
+
parsed
.DescendantTags
.OfType("title").IgnoreCase()
.First()
.Parent
.TypeEqualsIgnoreCase("HEAD")
- .ShouldBeTrue();
+ .ShouldBeTrue();
parsed
.DescendantTags
- .Count(x => x.Parent.TypeEqualsIgnoreCase("HTML"))
- .ShouldBeEqualTo(2); // head, body
-
+ .WithAttributeNamed("style")
+ .Count()
+ .ShouldBeEqualTo(2);
+
parsed
- .Body
+ .DescendantTags
+ .WithAttributeNamed("id")
+ .HavingValue("world")
+ .First()
.Content
- .ShouldBeEqualTo("Hello World");
+ .ShouldBeEqualTo("World");
## License
+note: the .Should... syntax comes from the [FluentAssert][FluentAssert] library.
+
[MIT License][mitlicense]
This project is part of [MVBA Law Commons][mvbalawcommons].
[mvbalawcommons]: http://code.google.com/p/mvbalaw-commons/
+[FluentAssert]: http://github.com/mvba/FluentAssert/
[mitlicense]: http://www.opensource.org/licenses/mit-license.php
Oops, something went wrong.

0 comments on commit c59430e

Please sign in to comment.