[ic] XML::Parser again...
Stefan Hornburg
racke at linuxia.de
Thu Jun 17 08:16:03 EDT 2004
On Mon, 14 Jun 2004 15:26:29 +0200
Carsten Jahnke <carstenjahnke at web.de> wrote:
> Hey folks,
>
> hopefully someone has experience using this module.
> the using tag and functionality around is running.
I'm using XML::Twig which is much more handy than XML::Parser in a global
usertag like that:
UserTag sql2xml HasEndTag
UserTag sql2xml Routine <<EOF
use XML::Twig;
sub {
my ($body) = @_;
my ($stmt, $aref, @tables, $twig, $root, $elt, $xml);
# parse sql statement to get information about tables etc.
eval {
$stmt = Vend::SQL_Parser->new($body);
};
if ($@) {
die ::errmsg("Bad SQL statement: %s\nQuery was: %s", $@, $body);
}
for ($stmt->tables()) {
push (@tables, $_->name());
}
# for ($stmt->columns()) {
# Log ("Column: " . $_->name());
# }
# only accept select statements
unless (lc($stmt->command()) eq 'select') {
die errmsg("[sql2xml] accepts only select statements (command was: %s)", $stmt->command());
}
# now we actually perform the query using the same data
# source as for mbs_article, which allows to use tables
# not registered with Interchange
$Tag->perl({tables => 'mbs_article'});
$aref = $Db{mbs_article}->query({sql => $body, hashref => 1});
# turn results into XML
$twig = new XML::Twig (PrettyPrint => 'indented',
EmptyTags => 'html');
$twig->parse(qq{<root></root>});
$root = $twig->root();
for (@$aref) {
$elt = $root->insert_new_elt('last_child', $tables[0], $_);
}
$xml = q{<?xml version="1.0" encoding="utf-8" ?>
};
$xml .= $twig->sprint();
return ($xml);
}
EOF
Cheers
Racke
--
Upcoming Talks and Presentations:
Linuxtag 2004, 25. Juni: Courier Mail Server (http://www.linuxtag.org/)
Perlworkshop 2004, 30. Juni: Entwicklung großer Perlanwendungen
am Beispiel von Interchange (http://www.perlworkshop.de/)
More information about the interchange-users
mailing list