| 1 | package CGI::OptimalQuery::XML; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | no warnings qw( uninitialized ); | ||
| 6 | use base 'CGI::OptimalQuery::Base'; | ||
| 7 | use CGI(); | ||
| 8 | |||
| 9 | sub output { | ||
| 10 | my $o = shift; | ||
| 11 | |||
| 12 | my $title = $o->{schema}->{title}; | ||
| 13 | $title =~ s/\W//g; | ||
| 14 | my @t = localtime; | ||
| 15 | $title .= '_'.($t[5] + 1900).($t[4] + 1).$t[3].$t[2].$t[1]; | ||
| 16 | |||
| 17 | $$o{output_handler}->(CGI::header(-type => 'text/xml', -attachment => "$title.xml"). | ||
| 18 | "<?xml version=\"1.0\"?>\n<OptimalQuery>\n"); | ||
| 19 | |||
| 20 | my @userselcols = @{ $o->get_usersel_cols }; | ||
| 21 | |||
| 22 | my $buf; | ||
| 23 | |||
| 24 | # print data | ||
| 25 | while (my $rec = $o->fetch()) { | ||
| 26 | $buf .= "<rec id=\"$$rec{U_ID}\">\n"; | ||
| 27 | foreach my $col (@userselcols) { | ||
| 28 | $buf .= " <$col>".$o->escape_html($o->get_val($col))."</$col>\n"; | ||
| 29 | } | ||
| 30 | $buf .= "</rec>\n"; | ||
| 31 | } | ||
| 32 | $buf .= "</OptimalQuery>"; | ||
| 33 | |||
| 34 | $$o{output_handler}->($buf); | ||
| 35 | |||
| 36 | $o->finish(); | ||
| 37 | return undef; | ||
| 38 | } | ||
| 39 | |||
| 40 | |||
| 41 | 1; |