http://www.perlmonks.org?node_id=475324

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

Esteemed monks,

I have a simple sub in my module which looks like this:

sub _view_xml { my $self = shift; my $xml = XMLin( "ttscall1.xml" ); print Dumper $xml; my $xml = XMLout( $xml, Rootname => 'campaign' ); print $xml; return $xml; }
The file contains some XML which is in exactly the structure specified for the particular API I need to send it to:
<campaign menuid="10118-2" action="0" > <phonenumbers > <phonenumber number="4167781583" callid="1234abc" > <prompts> <prompt promptid="2" tts="Hello, this is a test." /> </prompts > </phonenumber> </phonenumbers> </campaign>
When I dumpt the hash I get this:
$VAR1 = { 'menuid' => '10118-2', 'action' => '0', 'phonenumbers' => { 'phonenumber' => { 'number' => '4167781583', 'prompts' => { 'prompt' => { 'tts' => 'Hello, this is a test.', 'promptid' => '2' } }, 'callid' => '1234abc' } } };
Which is kinda what I expected. But when I ask for the XML back again, It gets compressed or something, and produces:
<campaign action="0" menuid="10118-2"> <phonenumbers name="phonenumber" callid="1234abc" number="4167781583 +"> <prompts name="prompt" promptid="2" tts="Hello, this is a test." / +> </phonenumbers> </campaign>
How do I get XML::Simple to output the XML in the same form it was to begin with?

What happens when I submit the XML to the API? I get this response:

<?xml version="1.0"?><campaign errorid="16" comment="XML parse error: +PHONENUMBER tag missing or misplaced." />
. And I figure the same thing will happen for the <prompt> as well except it doesn;t get so far as parsing that yet.

Your assistance is appreciated! jdtoronto