Well, i have been trying to get this to work for 30 minutes
now with no luck. I even pulled in one the test files from
the distro and it didn't "work":
There could be a bug in this version (0.89) or we could
both be missing how to properly use this module. My
suggestion is to (well, always explain what you
are trying to accomplish first!) pick another module. From
the docs, it appears that this one may have been designed
to be used with a database. If that is the case, then try
XML::Generator::DBI instead. I wrote a tutorial
on it over at XML::Generator::DBI Tutorial. Best of luck. :)
| [reply] [Watch: Dir/Any] [d/l] |
| [reply] [Watch: Dir/Any] |
I would wait at least a day before emailing the author -
maybe someone here at the Monastery will figure it out. If
and when you do email the author, be very consise and
polite (you know this ;)). Matts has written many XML modules and perhaps he has used this one before, you might
want to /msg him and invite him to look at your question.
mirod is another XML Wizard, he may have an alternative
for you.
Another outlet is
http://rt.cpan.org - if this is a bug, you can
report it to the author at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=XML-Generator-PerlData
| [reply] [Watch: Dir/Any] |
The output from XML::Generator::PerlData is SAX2, not SAX1, so you have to either run it through XML::Filter::SAX2toSAX1 before output to XML::Handler::YAWriter, or use XML::SAX::Writer to output it. | [reply] [Watch: Dir/Any] |
It looks like there is a problem with the module, either with the code or with the docs. For such problems with uncommon XML modules you should try asking on the perl-xml mailing list (Kip usually reads it). If you don't get an answer you can then try contacting the author and/or reporting the bug through rt.cpan.org.
In this case I would probably use a different module though. See below for a bunch of possibilities (there are many more, from XML::LibXML to XML::SAX::Writer):
#!/usr/bin/perl -w
use strict;
use Test::More qw(no_plan);
use XML::SemanticDiff;
use File::Slurp;
use Getopt::Std;
my %opt;
# -v is verbose, it displays the generated string for each test
getopts( 'v', \%opt);
# XML::SemanticDiff seems to only compare files, not strings
my $tmp_expected= "tmp.expected"; # temp file with expected result
my $tmp_result = "tmp.result"; # temp file with result
my %tests=( 'XML::Simple' => { sub => \&test_xml_simple, },
'XML::Writer' => { extra_modules => [ 'IO::Scalar' ],
sub => \&test_xml_writer,
},
'XML::Handler::YAWriter'
=> { sub => \&test_xml_handler_yawriter,
+ },
'XML::Twig' => { sub => \&test_xml_twig, },
);
write_file( $tmp_expected, <DATA>);
my $sem_diff= XML::SemanticDiff->new;
foreach my $module ( keys %tests)
{ my $test= $tests{$module};
my @modules= ($module);
push @modules, @{$test->{extra_modules}} if( $test->{extra_modules
+});
if( load_modules( @modules))
{ my $result= $test->{sub}->();
write_file( $tmp_result, $result);
my $diff= $sem_diff->compare( $tmp_expected, $tmp_result);
ok( ! $diff, $module) or diag( "got $result") ;
diag( "\n", $result, "\n\n") if( $opt{v});
}
else
{ SKIP: { skip( "$module not available", 1); }
}
}
unlink $tmp_expected, $tmp_result;
sub test_xml_simple
{ my $xml= { entry => { att1 => 'value1', att2 => 'value2', path =>
+{ content => 'path & text'} } };
return XMLout( $xml, keeproot => 1);
}
sub test_xml_writer
{ my $result;
my $output = IO::Scalar->new( \$result);
my $writer = XML::Writer->new(OUTPUT => $output);
$writer->startTag( entry => att1 => 'value1', att2 => 'value2');
$writer->dataElement( path => 'path & text');
$writer->endTag( 'entry');
$writer->end();
$output->close();
return $result;
}
sub test_xml_handler_yawriter
{ my $writer= XML::Handler::YAWriter->new( AsString => 1);
$writer->start_document;
$writer->start_element( { Name => 'entry', Attributes => { att1 =>
+ 'value1', att2 => 'value2'} } );
$writer->start_element( { Name => 'path' } );
$writer->characters( { Data => 'path & text' } );
$writer->end_element( { Name => 'path'} );
$writer->end_element( { Name => 'entry'} );
return $writer->end_document;
}
sub test_xml_twig
{ my $root= XML::Twig::Elt->new( entry => { att1 => 'value1', att2 =
+> 'value2' });
$root->insert_new_elt( path => "path & text");
return $root->sprint;
}
# a simple way of importing modules at run time
#sub load_modules
# { foreach (@_)
# { if(eval "require $_") { import $_; }
# else { return 0; }
# }
# return 1;
# }
# fun way
sub load_modules
{ ((eval "require $_" and import $_ or 1) or return 0) foreach (@_)
+; 1}
__DATA__
<entry att1="value1" att2="value2">
<!-- the & is here to test escaping -->
<path>path & text</path>
</entry>
| [reply] [Watch: Dir/Any] [d/l] |