On Monday 03 February 2003 17:45, David Chaplin-Loebell wrote:
> So...
>
> How are people turning information from SQL databases into XML for
> AxKit? I'm thinking the best way to do this would be to use a
> provider.  Has anyone done this yet?

Yup, I like the Provider-concept very much, and after asking here, it 
was explained to me when to use that vs. XSP. You might want to check 
the archives. 

> My concept is that a generic provider could take the rows returned by
> DBI and parse them into XML.
>
> So a query like:  SELECT id, name FROM foo
>
> which returns:
> id name
> -- ----
> 1  fish
> 2  cat
>
> would come out of the provider like so
>
> <foo>
>  <id>1</id>
>  <name>fish</name>
> </foo>
> <foo>
>  <id>1</id>
>  <name>fish</name>
> </foo>
>
> Has anyone already written this provider? 

I have not written a generic provider, but my as yet untested and 
unpublished "Article" provider does pretty much this. 

I'm using XML::Simple to do the transformation, and it looks something 
like this:
sub get_strref {
    my $self = shift;
    
# Get the data
    my $filename = $self->{filename};
    my $dbh = DBI->connect("dbi:Pg:dbname=mydb", "www-data", "")
        or die "Couldn't connect to database: " . DBI->errstr;
    my $sth = $dbh->prepare("SELECT * FROM articles WHERE filename=?");
    $sth->execute($filename);
    my $data = $sth->fetchrow_hashref;

# [snip] 

    $out .= XMLout($data, noattr => 1, rootname=>'article', 
suppressempty => undef);

# [snip] 

    return \$out;
}

Well, there's a lot of other things in there that I didn't include, but 
at least you may get an idea as to how I went about... :-) 

Cheers,

Kjetil
-- 
Kjetil Kjernsmo
Astrophysicist/IT Consultant/Skeptic/Ski-orienteer/Orienteer/Mountaineer
[EMAIL PROTECTED]  [EMAIL PROTECTED]  [EMAIL PROTECTED]
Homepage: http://www.kjetil.kjernsmo.net/        OpenPGP KeyID: 6A6A0BBC


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to