Google SVG Search III (1/2) - exploring XML | WebReference

Google SVG Search III (1/2) - exploring XML

Google SVG Search III

Wrapping up our Google API project, we finally convert the Perl script into a CGI and decorate the SVG output with a bit of HTML.

Going CGI

Perl has traditionally been popular for powering dynamic Web sites, not least due to the mighty but easy to use CGI module. A common technique is to use the same script for all requests of our little application, distinguishing between them through parameters:

RequestParameter pParameter q
Start HTML page(none or empty)(none or empty)
Response HTML page(none or empty)[search term]
Response embedded SVGsvg[search term]

In code this looks like:

#!/usr/bin/perl -w
use strict;
use CGI;
...
my $cgi = new CGI;
my $query = $cgi->param('q');
my $part = $cgi->param('p');
if (!defined($query) || $query eq "") {
  # print start HTML page
}
else {
  if (!defined($part) || $part eq "") {
    # print result HTML page
  }
  else {
    # access Google and print SVG results
  }
}

The start page consists of a header with a simple form for entering the search term:

  print <<EOF;
content-type: text/html
<html><head><title>Google SVG Search</title></head>
<body><h1>Google SVG Search</h1>
<form><input type=text name=q><input type=submit value='Google Search'></form>
</body></html>
EOF

Google SVG Search


And here come the results...


Produced by Michael Claßen

URL: https://www.webreference.com/xml/column57/index.html
Created: Jun 10, 2002
Revised: Jun 10, 2002