in reply to Re^2: XML tags using perl CGI
in thread XML tags using perl CGI
the standard also says if I set :html2, xhtml will go away (but it doesn't seem to have an effect)
Not sure which "standard" you're talking about there.
The ':html2' import tag just defines the set of functions that are imported into your symbol table. As you're using the Object interface to CGI.pm it has no effect at all on your program.
my $query = CGI->new; print $query->start_html(-title=>'Argh!', -background=>"../images/$SiteName.background.jpg", -link=>'brown', -vlink=>'#8b4513', -no_xhtml=>1, #this has no effect... -dtd=>'3.2 DTD' # this does the trick, but not listed in # the standard as to how to set it -- I # hope this is right... }
Ah, you seem to be using "standard" to mean "the CGI.pm documentation", which is slightly unusual :-)
The docs say:
If start_html()'s -dtd parameter specifies an HTML 2.0 or 3.2 DTD, XHTML will automatically be disabled without needing to use this pragma.
I think that means that you can override the whole DTD with this parameter. You can't just give it a string like "3.2 DTD", you need to give it a complete valid HTML DTD.
Also, you're using the -no_xhtml pragma wrong (which is why it has no effect). It's not a parameter to start_html() (and nowhere does the documentation imply that). It's in the list of pragmas - which are arguments you give in the "use CGI" statement.
I think that what you want is something like this:
use CGI '-no_xhtml'; my $c = CGI->new; print $c->start_html;
Which produces:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html lang="en-US"><head><title>Untitled Document</title> </head> <body>
And if I can just make one further comment. Embedding HTML markup in your code using the CGI.pm methods is a really nasty way to go about it. Your life will be much easier if you separate your HTML from your code using some kind of templating system (I recommend the Template Toolkit, but other options are available).
Update: s/usual/unusual/ - thanks to Corion for pointing it out.
"The first rule of Perl club is you do not talk about Perl club." -- Chip Salzenberg
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: XML tags using perl CGI
by pmcaveman (Novice) on Feb 06, 2007 at 12:35 UTC | |
by Joost (Canon) on Feb 06, 2007 at 13:09 UTC | |
by Bod (Parson) on Jan 14, 2024 at 00:34 UTC | |
by pryrt (Abbot) on Jan 14, 2024 at 17:17 UTC | |
by Bod (Parson) on Jan 14, 2024 at 20:30 UTC | |
| |
by Anonymous Monk on Jan 14, 2024 at 11:53 UTC | |
by davorg (Chancellor) on Feb 06, 2007 at 13:15 UTC | |
by pmcaveman (Novice) on Feb 06, 2007 at 13:48 UTC | |
by davorg (Chancellor) on Feb 06, 2007 at 14:04 UTC |