package SQL::Translator::Producer::XML::SQLFairy;
# -------------------------------------------------------------------
-# $Id: SQLFairy.pm,v 1.12 2004-07-08 19:05:26 grommit Exp $
+# $Id: SQLFairy.pm,v 1.14 2004-07-08 20:37:26 grommit Exp $
# -------------------------------------------------------------------
# Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>,
# darren chamberlain <darren@cpan.org>,
=head1 ARGS
-Doesn't take any extra arguments.
+=over 4
+
+=item add_prefix
+
+Set to true to use the default namespace prefix of 'sqlf', instead of using
+the default namespace for
+C<http://sqlfairy.sourceforge.net/sqlfairy.xml namespace>
+
+e.g.
+
+ <!-- add_prefix=0 -->
+ <field name="foo" />
+
+ <!-- add_prefix=1 -->
+ <sqlf:field name="foo" />
+
+=item prefix
+
+Set to the namespace prefix you want to use for the
+C<http://sqlfairy.sourceforge.net/sqlfairy.xml namespace>
+
+e.g.
+
+ <!-- prefix='foo' -->
+ <foo:field name="foo" />
+
+=back
+
+=head1 LEGACY FORMAT
+
+The previous version of the SQLFairy XML allowed the attributes of the the
+schema objects to be written as either xml attributes or as data elements, in
+any combination. The old producer could produce attribute only or data element
+only versions. While this allowed for lots of flexibility in writing the XML
+the result is a great many possible XML formats, not so good for DTD writing,
+XPathing etc! So we have moved to a fixed version described above.
+
+This version of the producer will now only produce the new style XML.
+To convert your old format files simply pass them through the translator;
+
+ sqlt -f XML-SQLFairy -t XML-SQLFairy schema-old.xml > schema-new.xml
=cut
use strict;
use vars qw[ $VERSION @EXPORT_OK ];
-$VERSION = sprintf "%d.%02d", q$Revision: 1.12 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.14 $ =~ /(\d+)\.(\d+)/;
use Exporter;
use base qw(Exporter);
my $translator = shift;
my $schema = $translator->schema;
$PArgs = $translator->producer_args;
+ my $newlines = defined $PArgs->{newlines} ? $PArgs->{newlines} : 1;
+ my $indent = defined $PArgs->{indent} ? $PArgs->{indent} : 2;
my $io = IO::Scalar->new;
+
+ my $prefix = "";
+ $prefix = $Name if $PArgs->{add_prefix};
+ $prefix = $PArgs->{prefix} if $PArgs->{prefix};
my $xml = XML::Writer->new(
OUTPUT => $io,
NAMESPACES => 1,
- PREFIX_MAP => { $Namespace => $Name },
- DATA_MODE => 1,
- DATA_INDENT => 2,
+ PREFIX_MAP => { $Namespace => $prefix },
+ DATA_MODE => $newlines,
+ DATA_INDENT => $indent,
);
$xml->xmlDecl('UTF-8');