dsheroh has asked for the wisdom of the Perl Monks concerning the following question:

Since my recent Element Express credit card processing post didn't turn up any information on existing Perl to interface with Element Express, I've done some checking and set about figuring out how to talk to them using XML::Simple. I'm just at the stage of working out how to generate the XML to submit to them so far, but it's coming together quite nicely. Aside from one little detail:
#!/usr/bin/perl use strict; use warnings; use XML::Simple qw(xml_in xml_out); my $req = { Foo => { Bar => 1, Baz => [ 2 ], }, }; print xml_out($req);
produces
<opt> <Foo Bar="1"> <Baz>2</Baz> </Foo> </opt>
which is just about what I expected... except where did the outer <opt>...</opt> come from and how do I get rid of it?

(Granted, it's possible that the <opt> doesn't matter and everything would work fine even with it there, but it's not present in any of Element Express's samples of writing the XML by hand with a series of print statements, so I'd prefer that it not be there. And also granted I could strip off the first and last lines to get rid of it, but that's ugly and just feels wrong. So I'd really prefer to find a way to get XML::Simple to let me specify the outermost container myself instead of wrapping everything in an <opt> for no apparent reason.)

Replies are listed 'Best First'.
Re: <opt>-less XML::Simple
by Anonymous Monk on Dec 18, 2007 at 03:52 UTC
    You just need to set the KeepRoot option:
    print xml_out($req, KeepRoot => 1);
    produces
    <Foo Bar="1"> <Baz>2</Baz> </Foo>
      Ah, excellent - thanks! I missed that option (obviously).