Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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 &amp; is here to test escaping --> <path>path &amp; text</path> </entry>

In reply to Re: XML::Generator::PerlData and attributes by mirod
in thread XML::Generator::PerlData and attributes by dda

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2024-04-23 19:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found