3

I remember once seeing a project a guy did where he write something like this in some language with json like strings which created pretty good html. Is there something like it i can use for C# or .NET

radio-box{ AName, [First|Second|Value:9|ItsLikeAnEnum]}, TextBox[user, password],
Checkbox[RememberMe:true, blah]}  //blah is default which is false
  • 3
    Is that easier? Doesn't look much less complex than actually writing html and html is more self describing... – Paddy Feb 12 '10 at 11:52
  • i dont know why ppl upvoted that comment. If the html can be that simple then the above is easier with no loss of info. Instead of changing every radio box (4 in the above case) you change it once instead of doing it multiple times by hand or making an error with find/replace. The above is less code and is easier to maintain. –  Mar 01 '10 at 11:57

4 Answers4

3

If you are using ASP.NET, there is the HTML Agility pack.

It has many helpers to deal with HTML. It will not be exactly as the format you are describing, but is still easier than dealing with raw HTML.

From the website:

This is an agile HTML parser that builds a read/write DOM and supports plain XPATH or XSLT (you actually don't HAVE to understand XPATH nor XSLT to use it, don't worry...). It is a .NET code library that allows you to parse "out of the web" HTML files. The parser is very tolerant with "real world" malformed HTML. The object model is very similar to what proposes System.Xml, but for HTML documents (or streams).

Oded
  • 489,969
  • 99
  • 883
  • 1,009
1

While it doesn't match the code sample in your question, but maybe you are looking for a templating language like NHaml? Here's a short NHaml example:

%h1 List of products
%ul
  - foreach (var product in products)
    %li= product.Name 

Is equivalent to:

<h1>List of products</h1>
<ul>
    <% foreach (var product in products) %>
        <li>
            <%= product.Name %>
        </li>
    <% } %>
</ul>
Jørn Schou-Rode
  • 37,718
  • 15
  • 88
  • 122
0

If you take a look at ASP.NET MVC there are a lot of built in html helper methods there, is that the kind of thing you mean?

http://www.asp.net/mvc

Steve
  • 8,469
  • 1
  • 26
  • 37
0

Not exactly the answer but there is the TagBuilder in Asp.Net MVC.

mtmk
  • 6,176
  • 27
  • 32