473,394 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Problems generating valid XHTML


Hi,

I am having difficulty getting the ASP.NET framework to generate valid
XHTML. My immediate problem surrounds user input in, for example, textbox
controls.

I consider characters such as less-than and ampersand perfectly valid in
user input. So I've disabled request validation by adding the following to my
web.config file.

<pages validateRequest="false" />

I have a simple page with an ASP.NET textbox and a submit button. I enter
the following test string the textbox control.

x < y && x > 0

I submit the page and allow it to simply re-render, which generates the
following HTML.

<input name="TextBox1" type="text" value="x < y &amp;& x > 0" id="TextBox1" />

This is not valid XHTML: the less-than and greater-than characters need to
be escaped.

Why is the framework escaping the ampersand but not the less-than and
greater-than characters?

I have tried to work around this by deriving from HtmlTextWriter and
overriding various methods so that I can HttpUtility.HtmlEncode() attribute
values, but the ampersand escaping appears to be hardcoded into the base
HtmlTextWriter: I always end up with double-escaping of the ampersands. e.g.
I get:

<input value="&lt;" />

instead of what I want, which is

<input value="<" />

Futher, because the HtmlTextWriter allows control authors to generate
whatever output they want via calls to Write(string), I don't think I can
have any control over the generated HTML at all. For example, I can do the
following in a custom control.

protected override void Render(HtmlTextWriter writer)
{
writer.Write("<input value=\"");
writer.Write("whatever I want & < in here");
writer.Write("\" >");
}

So the HtmlTextWriter has absolutely no idea whether I'm hacking together an
element, attribute or what.

I'm left wondering if the only way I can get valid XHTML is to override
every single Render() method of every control I want to use!? In which case
I'm losing just about all of the benefit of using built-in / 3rd-party
controls in the first place. Can anyone see a better way?

Thanks,
- Lee

Nov 19 '05 #1
4 1580

There are some escaping problems with my original post.

The HTML generated is:

value="X LT y ANDAND x GT y"

where the tokens LT, GT and AND represent single less-than, greater-than and
ampersand characters.

Likewise, using HtmlEncode() generates

value="ANDamp;lt;"

instead of

value="ANDlt;"

- Lee

Nov 19 '05 #2

Sorry, one more time:

The HTML generated is:

value="x LT y ANDamp;ANDamp; x GT y"

;-)

- Lee
Nov 19 '05 #3
Hi Lee,

Welcome to ASPNET newsgroup.
Regarding a procuding valid XHTML-compliant output in ASP.NET web
application, I've already seen many such topics in the online newsgroup and
some other web communities. Generally, we would have the following two
mechanism for asp.net 1.x pages currently:

1. Format output through page's Render method. In asp.net page's Render
event, we have the chance to call base's Render method to get the default
output content and do formatting on them.

2. Using Response Filter, asp.net provide us the ability to register a
response filter(request filter) on a certain http handler) at very begining
time when processing a request. And the Response Filter is just like a
Stream Chain which help us to intercept the output stream and do
modification. Here is a certain article discussing on this:

#ASP.NET Resources - Producing XHTML-Compliant Pages With Response ...
http://www.aspnetresources.com/artic...tpFilters.aspx

#ASP.NET 1.1 XHTML Compliance
http://weblogs.asp.net/ssivakumar/ar...05/252735.aspx

In addition, in asp.net 2.0 there seems also have some features on building
xhtml-compliant page,

#XHTML and Accessibility in ASP.NET Whidbey
http://weblogs.asp.net/scottgu/archi.../25/39620.aspx

Hope also helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| Thread-Topic: Problems generating valid XHTML
| thread-index: AcWu6wF8jG45/l+mR2CnOVdsf7Vwiw==
| X-WBNR-Posting-Host: 194.200.242.250
| From: "=?Utf-8?B?TGVlIENoYXBtYW4=?=" <Le********@newsgroup.nospam>
| References: <13**********************************@microsoft.co m>
<9F**********************************@microsoft.co m>
| Subject: RE: Problems generating valid XHTML
| Date: Thu, 1 Sep 2005 04:48:01 -0700
| Lines: 12
| Message-ID: <7B**********************************@microsoft.co m>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:121691
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
|
| Sorry, one more time:
|
| The HTML generated is:
|
| value="x LT y ANDamp;ANDamp; x GT y"
|
| ;-)
|
| - Lee
|
|
|

Nov 19 '05 #4

Steven,

Hmmm. Okay, that's not exactly what I was hoping for, but it'll do - I
guess. I suppose that at least an application that uses the filter method
will (hopefully) just need to drop the filter if it moves to ASP.NET 2.0...

Thanks,
- Lee
Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Michele Simionato | last post by:
What is the recommended way of generating HTML from Python? I know of HTMLGen and of few recipes in the Cookbook, but is there something which is more or less standard? Also, are there plans to...
5
by: Greg | last post by:
Hi everybody, so, I would like to use XML files for some parts of my website. I would like to respect W3C XHTML 1.1 recommendation. Then, I have these two docs : o My XML file: <?xml...
9
by: Francesco Moi | last post by:
Hello. I'm trying to build a RSS feed for my website. It starts: ----------------//--------------------- <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE rss PUBLIC "-//Netscape...
1
by: Jens Mueller | last post by:
Hi there, this is a Java-XML Question, so I am not sure whether this is the right place, haven't found anything better .... I try to convert a Java object to XML via SAX and let the FOP...
11
by: Dan Rubin | last post by:
HI everyone, lurking for a long time here, since I can usually solve my own problems, but here is one I'm stumped by. I've got a valid XHTML 1.0 Transitional layout, and all the CSS is valid as...
2
by: GIMME | last post by:
Background ... I've created a web application that allows a user to create an HTML application from IE. The application itself creates an XML representation of a XHTML form. The XHTML...
32
by: jp29 | last post by:
My take on problems composing, serving and rendering XHTML documents/web pages: 1. Typical conscientious web authors are producing XHTML documents (Web pages) that feature valid Markup and with...
8
by: Anthony Williams | last post by:
Morning all, I'm having a wee problem with a project I'm working on at the moment. I'm leading my company into producing a website, based upon Web Standards, which will be created using XHTML...
20
by: Alan Silver | last post by:
Hello, I have read about the problems that IE has when using a doctype of HTML 4.01 Transitional. I was advised to use Strict wherever possible. My question is, does the same apply to XHTML...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.