views:

136

answers:

3

I'm curious about the possibility of having a .NET class library that provides a complete abstraction of HTML (and perhaps CSS styles as well).

There would be a .NET class for every kind of HTML element, and even abstract classes (e.g. an abstract base class 'List', which 'OrderedList' and 'UnorderedList' extend).

The elements could be then added to a tree structure and rendered into a complete HTML page, including styles, by recursively calling 'Render' or something similar on each element instance.

I can imagine many ways such a library could be useful:

  • Build into the framework awareness of cross-browser rendering issues, or even multiple device/screen-size support. It might then be possible to build a web page once, and have it work with all the major browsers right off the bat.

  • Build an HTML editor with extremely good IntelliSense, etc using reflection. The editor could also have a WYSIWIG mode that allows dynamic re-arranging of elements, without generating malformed markup.

  • Do some very powerful auditing on the website's SEO, compliance, accessibility, etc.

  • Perform very granular, intelligent caching, right down to the element level.

Has anything similar to this been thought of or attempted already?

(Note: I realize that ASP.NET has something similar to this, under its "HtmlControls" namespace, but it doesn't represent the full range of HTML elements, and the elements it does include aren't modeled accurately enough. Also, the HTML elements on ASP.NET webforms are treated like text-files and parsed at runtime, rather than being compiled as strongly-typed classes.)

(Another note: I think Google Web Toolkit bears some similarity to this idea, although it's written in Java, and aimed more at Ajax/Javascript/DOM, rather than standards-based XHTML, CSS and Javascript)

A: 

Have you looked into ASP.NET? Your description (for the most part) sounds exactly like ASP.NET. Obviously it does not answer all your questions but it does answer most of them.

Andrew Hare
The picture in ASP.NET is not as rosy as his description. I see shortcomings in ASP.NET respective to every one of his bullets, although the basic description does seem to fit.
Robert Harvey
+1  A: 

I presume you know that this is already (partially) how ASP.NET works... ASP.NET has classes for some HTML classes, but it isn't fully built out. So while the general answer is yes, it has been thought of, it isn't a complete thought.

Michael Bray
+1  A: 

As long as you work with xhtml you should be able to use its xml schema to generate classes that you could build on. Then you could use xml (de)serialization to generate objects from your xhtml document.

Rune Grimstad