Search code examples
c#asp.netunit-testingweb-standards

Parsing HTML Fragments


What's the best way to parse fragments of HTML in C#?

For context, I've inherited an application that uses a great deal of composite controls, which is fine, but a good deal of the controls are rendered using a long sequence of literal controls, which is fairly terrifying. I'm trying to get the application into unit tests, and I want to get these controls under tests that will find out if they're generating well formed HTML, and in a dream solution, validate that HTML.


Solution

  • If the HTML is XHTML compliant, you can use the built in System.Xml namespace.