Fog Creek Software
Discussion Board




Welcome! and rules

Joel on Software

xhtml doesn't validate

i'm using C# to as the code behind for a webform.

When I add a control as follows:
....
Panel pnl = new Panel();
pnl.HorizontalAlign = HorizontalAlign.Left;
....

my html shows: <div align="Left">...

The problem is that the attribute has a capital "L" in left, and that doesn't validate for xhtml.

Is there anyway to force .NET to generate lowercase letters?


Thanks

Charles Reich
Thursday, April 10, 2003

For your own sanity, stop trying to do XHTML with ASP.NET's built-in controls. Actually, for your own sanity, stop doing XHTML period. It's a pointless hack anyway.

Brad (dotnetguy.techieswithcats.com)
Thursday, April 10, 2003

How is xhtml a "pointless hack"? It's a simple variation of HTML that conforms to the rules of XML (versus HTML which is 95% there), and the given HTML schema, and gives the greatest probability of no cross-platform problems. I think the only "pointless hack" is non XML validating HTML.

Dennis Forbes
Friday, April 11, 2003

XHTML is actually illegal SGML, because of the tag soup issues with self-contained tags like BR (placing a space between the tag and the / is the specific issue). It's sent down with a type of "text/html" and is thus always treated as tag soup.

If you wanted semantic XML inside your web app, you're infinitely better off with just stock XML in some schema that's more useful to you, then use XSL-T to transform it to HTML. The browsers don't care, and your users surely don't, either.

Brad (dotnetguy.techieswithcats.com)
Friday, April 11, 2003

I found an interim solution anyway to my problem...

Instead of using HorizontalAlign, I set the CssClass to "LeftAlign" which I defined as follows in my style sheet:

.LeftAlign
{
  TEXT-ALIGN: left;
}

Charles Reich
Wednesday, April 16, 2003

XHTML is not worthless.  It makes it much easier for programmatic access to your content later.  It also makes it easier to identify where the invalid code is when running through a validator (contrasted by the fact that it's harder to get it to validate as XHTML, until you get in the habit of writing XHTML all the time).

Imagine trying to write a program to spider all of your own pages and collect all of the copyright notices and fineprint.  It'd sure be easier if you knew your pages were valid XML and could just look for all divs with the class of "copyright" or "fineprint".  Sure, you could cobble together a regular expression that would be pretty good for this simple example, but it would be prone to minor exceptions (like newlines between the "<div " and the "class="fineprint").

That being said...

No, I don't think it's currently worth it to try and generate XHTML with ASP.NET.  Too many hoops to jump through for too little gain.

Richard Ponton
Wednesday, April 16, 2003

*  Recent Topics

*  Fog Creek Home