14 Oct 2003 15:16:39 UTC
- Distribution: Class-DBI-ToSax
- Module version: 0.10
- Source (raw)
- Browse (raw)
- How to Contribute
- Issues (0)
- Testers (423 / 1 / 2)
- KwaliteeBus factor: 0
- 89.87% Coverage
- License: perl_5
- Perl: v5.6.1
- Activity24 month
- Download (6.76KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest versionSEMANTICO semantico
Class::DBI::ToSax - turn database objects to SAX events
package My::DBI; # NB! Must come first in inheritance chain! use base qw( Class::DBI::ToSax Class::DBI ); # In the application... use XML::SAX::Writer; my $obj = My::DBI->retrieve( $x ); my $w = XML::SAX::Writer->new; $obj->to_sax( $w );
This module adds an extra method to Class::DBI, to_sax(). All the usual sorts of SAX handler can be passed in. The example above shows a writer to send the XML to stdout.
NB: This class must come first in the inheritance chain because it overrides ordinary Class::DBI methods.
The generated XML will have:
One wrapper element, which is the name of the table, with an id attribute. The id attribute will be the value of the primary key. If there are multiple primary keys, then each value will be present, separated by slashes.
One containing element for each column which has a scalar value.
One element for each has_a() relationship, which will be nested. The element will be named after the column name in the table which refers to it, so that the containing table might be exactly reconstructed using the XML output.
Zero or more elements for each has_many() relationship, each of which will be nested. The elements containing each nested row will be named after the table that they are in.
- to_sax( HANDLER, [ OPTS ] )
Transform the object into XML via SAX events on HANDLER. OPTS may be a series of key value pairs. Valid keys include:
If true, do not recursively call contained objects. There will still be an element for the contained object, but it will only contain an id attribute.
Optionally, the value of norecurse may be set to a hash ref, in which case, each key will be the name of a table which is not to be recursed into. This can be used to avoid retrieveing too much data from the database when it is not needed.
If norecurse is set to a coderef, then it will be called. It is expected to return a true value if it wants recursion stopped at that point. It will be passed a list of objects back up to the original caller in order to help it make its decision.
If true, then do not call start_document() and end_document(). This lets you insert a stream of SAX events for your Class::DBI objects into another stream of SAX events.
If you want to generate XML directly from the database without using Class::DBI, look at XML::Generator::DBI.
We should be able to flag some fields as containing CDATA. I'm not sure of the best interface to do this, however.
Dominic Mitchell, <email@example.com<gt>
Copyright 2003 by semantico
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Module Install Instructions
To install Class::DBI::ToSax, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell install Class::DBI::ToSax
For more information on module installation, please visit the detailed CPAN module installation guide.