Keith, if your ASP.NET page contains arbitrary Server Controls, then it will
generate arbitrary HTML. A control can generate whatever HTML it likes -
ASP.NET has no say in the matter.
Also, if you need to translate some small, fixed number of ASP.NET pages
which you are designing, then I'm sure you can do the translation. But if
others are working on the project, or if the project has more than a few
pages or exists over more than a short span of time, then you will rapidly
approach "arbitrary".
Also, to the extent that you are not the person controlling the HTML to be
translated, then you will not have control over when the generator of that
HTML should decide to change the details of how it's generated. You'll be in
the same position as some programmers I've met who wrote code which depended
on the precise text of an error message generated by another piece of code,
and who were disappointed when the error message changed to use proper
grammar.
It's because of things like these that I asked whether there was some
general algorithm for translating valid HTML into valid XHTML. It seems to
me that only such an algorithm will succeed in the long run.
Also, it sounds to me as though you are at the beginning of a process which
may involve you using your translator for the next three years or so - until
you can deploy the hypothetical version of ASP.NET which is fully XHTML
compliant, along with compliant versions of all of the controls used by all
of your pages. Keep in mind that compliance to your requirements may perhaps
not be achieved in version 2.0 of ASP.NET, even if it _is_ an obvious
feature to include in a 2.0 release. Talk to someone about Microsoft Visual
C++ and how one is always waiting for the "next release" for full standards
compliance.
My recommendation about the Government clearly indicating their requirements
to Microsoft ( ;-) ) were not entirely facetious. Given what I perceive as
the likely course you're about to embark upon (making someone else's code do
something they never intended that it should do), I thought that it may be
early enough in Microsoft's development cycle that forceful action could
cause them to actually meet your requirements in the 2.0 timeframe. "I can't
use your product and so won't be buying any" is more likely to cause the
desired reaction than "I can use your product, but only with this workaround
I've written and maintain, and we'll be buying it anyway, so you needn't
lose sleep over it".
BTW, you say that this is a UK standard, but I wonder if there are similar
EU standards? Collective action might be even more effective.
Any answers containing some useful code?
Oh, you wanted code, did you?
Well, before I go into code, I'll quickly mention that the "political"
solutions I discussed might be effective in causing Microsoft to give you a
supported solution to your problem in addition to focusing their attention
on the issue for the 2.0 release. It might also put you in continued contact
with a person at Microsoft who may act as a conduit into Microsoft for your
concerns on this matter. In other words, you might require them to provide
you with a workaround as a condition of purchase.
You have a few choices given the appropriate translation algorithm. You can
derive all of your pages from a single base class, which itself derives from
System.Web.UI.Page. This class would override the Render method:
/// <summary>
/// Render - override to modify the output of a derived page
/// </summary>
/// <param name="writer">The HtmlTextWriter to send the output
to</param>
protected override void Render(HtmlTextWriter writer)
{
System.IO.StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter localWriter = new HtmlTextWriter(sw);
base.Render(localWriter);
string output = sw.ToString();
// Do what you like with the output
output = output.ToUpper();
writer.Write(output);
}
The other option involves using Response.Filter. Replace that with a stream
of your choice to modify the output as it comes out. That will be less
convenient to program for your needs, since the output does not come out all
at once.
Good Luck,
John Saunders
Internet Engineer
(e-mail address removed)
P.S. Out of curiosity and self-interest, I wonder: with which version of the
XHTML standard does the UK Government require compliance? Since I work at a
UK-based company creating web sites, this might become interesting to me.