1 package SQL::Translator::Producer::XML;
3 # -------------------------------------------------------------------
4 # $Id: XML.pm,v 1.4 2002-11-28 04:21:07 kycl4rk Exp $
5 # -------------------------------------------------------------------
6 # Copyright (C) 2002 Ken Y. Clark <kclark@cpan.org>,
7 # darren chamberlain <darren@cpan.org>
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation; version 2.
13 # This program is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22 # -------------------------------------------------------------------
26 SQL::Translator::Producer::XML - XML output
30 use SQL::Translator::Producer::XML;
34 Meant to create some sort of usable XML output.
39 use vars qw[ $VERSION $XML ];
40 $VERSION = sprintf "%d.%02d", q$Revision: 1.4 $ =~ /(\d+)\.(\d+)/;
42 # -------------------------------------------------------------------
44 my ( $translator, $data ) = @_;
46 aggregate( '<schema>', $indent );
51 sort { $a->[0] <=> $b->[0] }
52 map { [ $_->{'order'}, $_ ] }
55 aggregate( '<table>', $indent );
58 aggregate( "<name>$table->{'table_name'}</name>", $indent );
59 aggregate( "<order>$table->{'order'}</order>", $indent );
64 aggregate( '<fields>', $indent );
67 sort { $a->[0] <=> $b->[0] }
68 map { [ $_->{'order'}, $_ ] }
69 values %{ $table->{'fields'} }
71 aggregate( '<field>', ++$indent );
74 for my $key ( keys %$field ) {
75 my $val = defined $field->{ $key } ? $field->{ $key } : '';
76 $val = ref $val eq 'ARRAY' ? join(',', @$val) : $val;
77 aggregate( "<$key>$val</$key>", $indent );
81 aggregate( "</field>", $indent-- );
83 aggregate( "</fields>", $indent );
88 aggregate( '<indices>', $indent );
89 for my $index ( @{ $table->{'indices'} } ) {
90 aggregate( '<index>', ++$indent );
93 for my $key ( keys %$index ) {
94 my $val = defined $index->{ $key } ? $index->{ $key } : '';
95 $val = ref $val eq 'ARRAY' ? join(',', @$val) : $val;
96 aggregate( "<$key>$val</$key>", $indent );
100 aggregate( "</index>", $indent-- );
102 aggregate( "</indices>", $indent );
105 aggregate( "</table>", $indent );
109 aggregate( '</schema>', $indent );
114 # -------------------------------------------------------------------
116 my ( $text, $indent ) = @_;
117 $XML .= (' ' x $indent) . "$text\n";
122 # -------------------------------------------------------------------
123 # The eyes of fire, the nostrils of air,
124 # The mouth of water, the beard of earth.
126 # -------------------------------------------------------------------
132 Ken Y. Clark E<lt>kclark@cpan.orgE<gt>