Google Answers Logo
View Question
 
Q: Robust method of generating perfect (well-formed) XHTML documents ( No Answer,   1 Comment )
Question  
Subject: Robust method of generating perfect (well-formed) XHTML documents
Category: Computers > Programming
Asked by: carbon-ga
List Price: $20.00
Posted: 29 Jun 2005 20:41 PDT
Expires: 30 Jun 2005 11:37 PDT
Question ID: 538600
I'm making a database-driven site that will mainly be Java servlets on
Tomcat. I want all my generated XHTML to be well formed. That is, I
want to have peace of mind knowing that my programs (servlets) are
incapable of generating web pages that would not validate with the W3
validator.

I've checked a couple of different ways of doing this. I made custom
tags in JSP; I'm not really satisifed with this way because although I
can ensure that my custom tags will generate perfect XHTML, I can't be
sure about the template text. Errors in the template text result in
errors in the resulting web pages. Even if there is no template text,
I can't be sure that my JSP actually results in a document that would
validate. Also, custom tags are unpleasant because one has to put
XHTML code in Java strings.

Lately, I've been looking at XSLT. It could be that I just don't
understand it well enough, but it seems like it suffers from the same
template text problem. I can retrieve values from the XML tree, but
that value goes between tags that are just template text. I could put
the value I just got between some fictional illegal tags. Could I
write a lot of named templates that produce correct XHTML so that I do
not *have* any template text in my XSLT?

I'm willing to look at other techniques for generating pages. My main
concern is to have a robust method of generating correctly formed
pages, pages that would validate.
Answer  
There is no answer at this time.

Comments  
Subject: Re: Robust method of generating perfect (well-formed) XHTML documents
From: mathtalk-ga on 30 Jun 2005 10:13 PDT
 
The phrase "well-formed" generally applies to whether a document
complies with the XML standard (with some quibbling about whether
external entities are to be parsed or not).

On the other hand validating an XML document as proper XHTML would, at
least in the first instance, require reference to the W3C's standard:

[XHTML 1.0 (2nd edition)]
http://www.w3.org/TR/xhtml1/

and in particular the Document Type Definitions (DTDs) provided there.

Obviously the simpler your XHTML generation is, the more easily
convinced you might be that it cannot possibly generate bad XHTML. 
What I'm not clear about are the "solutions" you considered, custom
tags and XSLT, as they relate to this concern.

It sounds as if the general problem is a need to include some
tag-delimited content in the input (which I think you are referencing
or wrapping with your custom tags), and it is essential to your
application to be able to retrieve this special content later on.

Using XSLT "templates" does seem like a robust way to generate
well-formed XML, and XHTML as a specific target.  Of course the price
one pays is that XSLT takes a well-formed XML document as input, so in
part the checking of well-formedness is simply shifted from one place
to another.  Whether this is progress or not will depend, I'd guess,
on the nature of your input.

The phrase "template text" entered your discussion for both these
options, but probably the picture I made in connection with XSLT isn't
accurate.  I've used named templates a fair amount in XSLT, to help
with managing recursion and making effective reuse of "subroutine"
templates that implement "global" rules involving parameters.  These
might very well be a key ingredient in making the XSLT code as simple
as possible (and no simpler!).

One strategy would be a generate-and-test strategy, in which the
output of each servlet is validated as XHTML, and discarded if found
to have errors (logging the inputs and errors for later analysis). 
This may sound like a lot of overhead, but if the application is
complex enough that proper XHTML generation has proved difficult to
manage, then a systematic regression on errors may be the most
productive technique going forward.


regards, mathtalk-ga

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy