Subject: | Pretty printing XML when tracing |
SOAP::Lite's tracing facility is very useful, but it's diminished
because it traces the XML sent back and forth directly.
I've been working with a remote service that sends a large unformatted
block of XML that was difficult to diagnose.
I worked around it with this snippet of code.
my $can_xml_tidy = eval { require XML::Tidy; 1; };
sub trace {
if(shift) {
SOAP::Lite->import(+trace => [ debug => \&_log ]);
} else {
SOAP::Lite->import(+trace => -all);
}
return;
}
sub _log {
my $in = shift;
my($header, $body) = split(/\n\n/, $in);
print $header, "\n\n";
if($can_xml_tidy) {
my $tidy = XML::Tidy->new(xml => $body);
$tidy->tidy();
print $tidy->toString();
} else {
print $body;
}
}
So, if XML::Tidy's installed it's used to pretty-print the dumped XML.
Would you consider adding this functionality as an option (off by
default)?