Estemed monks,

I have an XML document which I parse using XML::Simple, I then try to modify it and then output it again as a string using XML::Simple. But the structure changes subtly and I am at a loss as to what I need to do:

#!/usr/bin/perl -w use strict; use XML::Simple; use Data::Dumper; my $self; my $pr_no_attach_xml; $pr_no_attach_xml = qq~<?xml version="1.0" encoding="UTF-8" ?> <voice_broadcast_info xmlns="http://www.obfuscated.com" xmlns:xsi="htt +p://www.w3.org/2001/XMLSchema-instance"> <SchemaVersion>1.0</SchemaVersion> <login_key> <user_id>173794</user_id> <user_password>223344</user_password> </login_key> <voice_broadcast_options> <billing_code>ABC123456</billing_code> <start_hour>0</start_hour> <end_hour>23</end_hour> <release_date>2003-10-01T23:59:59</release_date> <in_house_flag>false</in_house_flag> <max_successful>0</max_successful> <delivery_type>both</delivery_type> </voice_broadcast_options> <voice_recipient_list> <voice_recipient> <voice_recipient_number>1AREACODENUMBER</voice_recipient_numb +er> <voice_recipient_name>Me</voice_recipient_name> <voice_recipient_reference>bc-voice-1</voice_recipient_refere +nce> </voice_recipient> <voice_recipient> <voice_recipient_number>1AREACODENUMBER</voice_recipient_numb +er> <voice_recipient_name>Me</voice_recipient_name> <voice_recipient_reference>bc-voice-2</voice_recipient_refere +nce> </voice_recipient> </voice_recipient_list> <voice_answer_file vcast_file_content_type="audio/wav" vcast_file_e +ncoding_type="base64" vcast_file_name="TESTABC123" vcast_file_extension="wav" delivery_answer_type="voice" vcast_fi +le_desc="TESTABC123"></voice_answer_file> <machine_answer_file vcast_file_content_type="audio/wav" vcast_file_e +ncoding_type="base64" vcast_file_name="TESTABC123" vcast_file_extension="wav" delivery_answer_type="machine" vcast_ +file_desc="TESTABC123"></machine_answer_file> </voice_broadcast_info>~; my $xs = XML::Simple->new( KeepRoot => 1, GroupTags => { voice_recipient_list => 'voice_recipient' }, KeyAttr => [ 'name' ], ); $self->{_upload_hash} = $xs->XMLin( $pr_no_attach_xml ); print Dumper $self->{_upload_hash}; # Now modify the XML a little: $self->{_upload_hash}->{voice_broadcast_info}->{voice_recipient_list +} = [ { 'voice_recipient' => { 'voice_recipient_number' => '14169999999', 'voice_recipient_name' => 'John Day - 1', 'voice_recipient_reference' => 'bc-voice-1' } }, { 'voice_recipient' => { 'voice_recipient_number' => '14169999999', 'voice_recipient_name' => 'John Day - 2', 'voice_recipient_reference' => 'bc-voice-1' } } ]; my $xml = $xs->XMLout( $self->{_upload_hash}, attrIndent => 1 ); print "\nThrough the pipe - XML::Simple :\n\n$xml\n";
As you can see the output is not the same as the input! WHat I need is XML like this:
<voice_recipient_list> <voice_recipient> <voice_recipient_number>1AREACODENUMBER</voice_recipient_numb +er> <voice_recipient_name>Me</voice_recipient_name> <voice_recipient_reference>bc-voice-1</voice_recipient_refere +nce> </voice_recipient>
Rather than like this:
<voice_recipient name="voice_recipient" voice_recipient_name="John Day - 1" voice_recipient_number="14167781583" voice_recipient_reference="bc-voice-1" />
Where am I going wrong? Thanks, jdtoronto

In reply to XML::Simple not producing what I expect by jdtoronto

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.