1 package SQL::Translator::Producer::XML;
3 # -------------------------------------------------------------------
4 # $Id: XML.pm,v 1.5 2003-01-27 17:04:48 dlc Exp $
5 # -------------------------------------------------------------------
6 # Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>,
7 # darren chamberlain <darren@cpan.org>,
8 # Chris Mungall <cjm@fruitfly.org>
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License as
12 # published by the Free Software Foundation; version 2.
14 # This program is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
23 # -------------------------------------------------------------------
27 SQL::Translator::Producer::XML - XML output
31 use SQL::Translator::Producer::XML;
35 Meant to create some sort of usable XML output.
40 use vars qw[ $VERSION $XML ];
41 $VERSION = sprintf "%d.%02d", q$Revision: 1.5 $ =~ /(\d+)\.(\d+)/;
43 # -------------------------------------------------------------------
45 my ( $translator, $data ) = @_;
47 aggregate( '<schema>', $indent );
52 sort { $a->[0] <=> $b->[0] }
53 map { [ $_->{'order'}, $_ ] }
56 aggregate( '<table>', $indent );
59 aggregate( "<name>$table->{'table_name'}</name>", $indent );
60 aggregate( "<order>$table->{'order'}</order>", $indent );
65 aggregate( '<fields>', $indent );
68 sort { $a->[0] <=> $b->[0] }
69 map { [ $_->{'order'}, $_ ] }
70 values %{ $table->{'fields'} }
72 aggregate( '<field>', ++$indent );
75 for my $key ( keys %$field ) {
76 my $val = defined $field->{ $key } ? $field->{ $key } : '';
77 $val = ref $val eq 'ARRAY' ? join(',', @$val) : $val;
78 aggregate( "<$key>$val</$key>", $indent );
82 aggregate( "</field>", $indent-- );
84 aggregate( "</fields>", $indent );
89 aggregate( '<indices>', $indent );
90 for my $index ( @{ $table->{'indices'} } ) {
91 aggregate( '<index>', ++$indent );
94 for my $key ( keys %$index ) {
95 my $val = defined $index->{ $key } ? $index->{ $key } : '';
96 $val = ref $val eq 'ARRAY' ? join(',', @$val) : $val;
97 aggregate( "<$key>$val</$key>", $indent );
101 aggregate( "</index>", $indent-- );
103 aggregate( "</indices>", $indent );
106 aggregate( "</table>", $indent );
110 aggregate( '</schema>', $indent );
115 # -------------------------------------------------------------------
117 my ( $text, $indent ) = @_;
118 $XML .= (' ' x $indent) . "$text\n";
123 # -------------------------------------------------------------------
124 # The eyes of fire, the nostrils of air,
125 # The mouth of water, the beard of earth.
127 # -------------------------------------------------------------------
133 Ken Y. Clark E<lt>kclark@cpan.orgE<gt>