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:
As you can see the output is not the same as the input! WHat I need is XML like this:#!/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";
Rather than 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>
Where am I going wrong? Thanks, jdtoronto<voice_recipient name="voice_recipient" voice_recipient_name="John Day - 1" voice_recipient_number="14167781583" voice_recipient_reference="bc-voice-1" />
In reply to XML::Simple not producing what I expect by jdtoronto
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |