473,748 Members | 3,107 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Htm lEncode() 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(HtmlText Writer writer)
{
writer.Write("< input value=\"");
writer.Write("w hatever 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 1604

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;l t;"

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+mR2CnOVdsf7Vw iw==
| X-WBNR-Posting-Host: 194.200.242.250
| From: "=?Utf-8?B?TGVlIENoYXB tYW4=?=" <Le********@new sgroup.nospam>
| References: <13************ *************** *******@microso ft.com>
<9F************ *************** *******@microso ft.com>
| Subject: RE: Problems generating valid XHTML
| Date: Thu, 1 Sep 2005 04:48:01 -0700
| Lines: 12
| Message-ID: <7B************ *************** *******@microso ft.com>
| 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.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.p hx.gbl 10.40.2.250
| Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GXA03.phx.gbl
| Xref: TK2MSFTNGXA01.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:1216 91
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.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
2393
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 include a module for HTML generation in the standard library? I really would like to see some standardization in this area. Michele Simionato
5
2413
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 version="1.0" encoding="ISO-8859-1"?> <?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>
9
2961
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 Communications//DTD RSS 0.91//EN" "http://my.netscape.com/publish/formats/rss-0.91.dtd"> <rss version="0.91"> ----------------//----------------------
1
3108
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 Transformer convert that via XSLT to valid XSL-FO. So I define a SAXReader which fires the SAX Events for the Java Object. This works fine and the Transformation to PDF is ok. However, I have one object which contains an XHTML String and the tags
11
2800
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 well (plenty of warnings, but I'm not worried about that), and I'm making use of the float property without any problems EXCEPT for one page (coloured backgrounds added for clarity): http://autographquartet.com/contact.php
2
1459
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 representation can be saved as a string and recreated. (The application also has a crude workflow aspect - so XMHTML forms can be created and assigned a workflow. Forget I said anything about
32
4531
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 the content (MIME) type specified as text/html (http://keystonewebsites.com/articles/mime_type.php). These pages are then loaded on to their Server where they are served to Rendering Agents (browsers) as HTML (SGML application) documents with no...
8
1956
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 and CSS, and powered by ASP.NET. My first problem, which I'm near to solving, was that ASP.NET doesn't produce valid XHTML output. We don't want to spend money on third-party components, and we can't wait for ASP.NET 2.0, so we needed to find a
20
2579
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 1.0 Transitional? I develop sites using ASP.NET, which emits valid XHTML 1.0 Transitional, but not XHTML 1.0 Strict (for example, it includes a hidden form field with the name of _VIEWSTATE, which isn't valid in Strict, but is in Transitional).
0
8826
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9316
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9241
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8239
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4597
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4867
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2777
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.