L
lievemario
Hello,
I have written the following perl program,
this is what is does:
- it gets input from a form (a person_id)
- then it executes a query
- transform this result to an xml file
- then transform the xml file via xsl file to output in the browser.
Now the following errors appear:
- first of all, I don't know why, but the script is not able to open / write
person.xml anymore
- second, when I have such an xml file, the script is not able to produce
the output,
I get a CGI timeout error.
(Just for info; I call the script via the following line in the form
application:
<form action="person2.cgi?person_id=$person_id" method="POST">
)
I have search a long time, but I can not solve the problem.
- another question I also have;
it is my intention to execute 1 or more queries (depending on the
@details the
user selected in the form). How can I combine all these xml files/xsl to
one output?
Hope I get some solution.
Thanks a lot!!
----------------------------------------------------------------------------
#!/usr/bin/perl
# use strict;
use DBI;
use XML::Generator:BI;
use XML::Handler::YAWriter;
use XML:arser;
use XML::XSLT;
use CGI qw(param);
my $xslfile = "CGI\\details.xsl";
# create a DBI connection
my $dbh = DBI->connect ("DBI:mysql:rd", "root", "",
{ RaiseError => 1,
PrintError => 0
});
# instantiate a new XML::Handler::YAWriter object
my $out = XML::Handler::YAWriter-> new(
AsFile => "CGI\\person.xml",
Pretty => {PrettyWhiteNewline => 1,
PrettyWhiteIndent => 1,
CatchEmptyElement => 1,
CatchWhiteSpace => 1
},
Encoding => "ISO-8859-1",
);
# instantiate a new XML::Generator:BI object
my $gen = XML::Generator:BI->new(
Handler => $out,
dbh => $dbh,
RootElement => 'Description',
RowElement => 'Person'
);
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/'//g;
$value =~ s/&/and/g;
$value =~ s/\"//g;
$value =~ s/\+//g;
$FORM{$name} = $value;
}
my @details = ("data","team","pubs","other");
foreach $x (@details) {
if ($FORM{$x} == 1) {
if($x eq "data") {
data_query();
}
#print "You picked $x.\n";
}
}
my $xmlparser = new XML:arser(ProtocolEncoding => "ISO-8859-1");
my $input = "CGI\\person.xml";
$xmlparser ->setHandlers(Start => \&start_handler,
End => \&end_handler,
Char => \&char_handler);
$xmlparser ->parsefile($input);
# The handlers for the XML Parser.
sub start_handler
{
my $expat = shift; my $element = shift;
# element is the name of the tag
print $startsub{$element};
# Handle the attributes
while (@_) {
my $att = shift;
my $val = shift;
print "$att=$val ";
}
}
sub end_handler
{
my $expat = shift; my $element = shift;
print $endsub{$element};
}
sub char_handler
{
my ($p, $data) = @_;
#print $data;
}
my $xslparser = XML::XSLT->new($xslfile);
my $result = $xslparser->serve("CGI\\person.xml", http_headers => 0,
xml_version => 0, xml_declaration => 0);
$result = "Content-Type: text/html\n\n" . $result;
print $result;
my $person_id = param("person_id");
print $person_id;
sub data_query {
# define the SQL query
my $query1 = "SELECT p.person_id,
p.name,
p.first_name,
p.phone,
p.fax,
p.email
FROM list_personnel p
WHERE p.person_id = ?;
";
#my $sth1 = $dbh->prepare($query1);
$gen->execute($query1,$person_id);
}
----------------------------------------------------------------------------
I have written the following perl program,
this is what is does:
- it gets input from a form (a person_id)
- then it executes a query
- transform this result to an xml file
- then transform the xml file via xsl file to output in the browser.
Now the following errors appear:
- first of all, I don't know why, but the script is not able to open / write
person.xml anymore
- second, when I have such an xml file, the script is not able to produce
the output,
I get a CGI timeout error.
(Just for info; I call the script via the following line in the form
application:
<form action="person2.cgi?person_id=$person_id" method="POST">
)
I have search a long time, but I can not solve the problem.
- another question I also have;
it is my intention to execute 1 or more queries (depending on the
@details the
user selected in the form). How can I combine all these xml files/xsl to
one output?
Hope I get some solution.
Thanks a lot!!
----------------------------------------------------------------------------
#!/usr/bin/perl
# use strict;
use DBI;
use XML::Generator:BI;
use XML::Handler::YAWriter;
use XML:arser;
use XML::XSLT;
use CGI qw(param);
my $xslfile = "CGI\\details.xsl";
# create a DBI connection
my $dbh = DBI->connect ("DBI:mysql:rd", "root", "",
{ RaiseError => 1,
PrintError => 0
});
# instantiate a new XML::Handler::YAWriter object
my $out = XML::Handler::YAWriter-> new(
AsFile => "CGI\\person.xml",
Pretty => {PrettyWhiteNewline => 1,
PrettyWhiteIndent => 1,
CatchEmptyElement => 1,
CatchWhiteSpace => 1
},
Encoding => "ISO-8859-1",
);
# instantiate a new XML::Generator:BI object
my $gen = XML::Generator:BI->new(
Handler => $out,
dbh => $dbh,
RootElement => 'Description',
RowElement => 'Person'
);
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/'//g;
$value =~ s/&/and/g;
$value =~ s/\"//g;
$value =~ s/\+//g;
$FORM{$name} = $value;
}
my @details = ("data","team","pubs","other");
foreach $x (@details) {
if ($FORM{$x} == 1) {
if($x eq "data") {
data_query();
}
#print "You picked $x.\n";
}
}
my $xmlparser = new XML:arser(ProtocolEncoding => "ISO-8859-1");
my $input = "CGI\\person.xml";
$xmlparser ->setHandlers(Start => \&start_handler,
End => \&end_handler,
Char => \&char_handler);
$xmlparser ->parsefile($input);
# The handlers for the XML Parser.
sub start_handler
{
my $expat = shift; my $element = shift;
# element is the name of the tag
print $startsub{$element};
# Handle the attributes
while (@_) {
my $att = shift;
my $val = shift;
print "$att=$val ";
}
}
sub end_handler
{
my $expat = shift; my $element = shift;
print $endsub{$element};
}
sub char_handler
{
my ($p, $data) = @_;
#print $data;
}
my $xslparser = XML::XSLT->new($xslfile);
my $result = $xslparser->serve("CGI\\person.xml", http_headers => 0,
xml_version => 0, xml_declaration => 0);
$result = "Content-Type: text/html\n\n" . $result;
print $result;
my $person_id = param("person_id");
print $person_id;
sub data_query {
# define the SQL query
my $query1 = "SELECT p.person_id,
p.name,
p.first_name,
p.phone,
p.fax,
p.email
FROM list_personnel p
WHERE p.person_id = ?;
";
#my $sth1 = $dbh->prepare($query1);
$gen->execute($query1,$person_id);
}
----------------------------------------------------------------------------