XML::Simple Help!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting XML::Simple Help!
# 1  
Old 12-28-2010
XML::Simple Help!

I can loop through each roomtype but if a roomtype has more that one mealtype I get this error:
Not a HASH reference

The ForceArray option is enabled. Please Help!


This is the dump from the XML that is begin returned to me:
---------------------------------------------------------------

Code:
$VAR1 = {
          'success' => 'true',
          'data' => {
                    'bb' => {
                            'roomtypes' => {
                                           'roomtype' => [
                                                         {
                                                           'rtimage' => '10002-2.jpg',
                                                           'ratescheme' => '1',
                                                           'rtid' => '2',
                                                           'roomsfree' => '2',
                                                           'childpolicy' => {
                                                                            'general' => '2 - 12 years stay',
                                                                            'allowchild2' => 'Y',
                                                                            'allowchild1' => 'Y'
                                                                          },
                                                           'mealtypes' => {
                                                                          'mealtype' => [
                                                                                        {
                                                                                          'defaultmealtype' => 'true',
                                                                                          'rates' => {
                                                                                                     'pax3' => '1180.00',
                                                                                                     'pax2' => '930.00',
                                                                                                     'pax4' => '1405.00',
                                                                                                     'pax1' => '550.00'
                                                                                                   },
                                                                                          'mealtypedesc' => 'Bed & Breakfast',
                                                                                          'rateid' => '6'
                                                                                        },
                                                                                        {
                                                                                          'rates' => {
                                                                                                     'pax3' => '850.00',
                                                                                                     'pax2' => '700.00',
                                                                                                     'pax4' => '975.00',
                                                                                                     'pax1' => '450.00'
                                                                                                   },
                                                                                          'mealtypedesc' => 'Self-catering',
                                                                                          'rateid' => '7'
                                                                                        }
                                                                                      ]
                                                                        },
                                                           'maxoccupancy' => '6',
                                                           'minlos' => '0',

                                                         },
                                                         {
                                                           'ratescheme' => '1',
                                                           'rtid' => '1',
                                                           'roomsfree' => '5',
                                                           'description' => 'Double bed',
                                                           'childpolicy' => {
                                                                            'general' => '2 - 12 years stay',
                                                                            'allowchild2' => 'Y',
                                                                            'allowchild1' => 'Y'
                                                                          },
                                                           'mealtypes' => {
                                                                          'mealtype' => {
                                                                                        'defaultmealtype' => 'true',
                                                                                        'rates' => {
                                                                                                   'pax2' => '800.00',
                                                                                                   'pax1' => '500.00'
                                                                                                 },
                                                                                        'mealtypedesc' => 'B&B',
                                                                                        'rateid' => '5'
                                                                                      }
                                                                        },
                                                           'maxoccupancy' => '2',
                                                           'minlos' => '0',
                                                         }
                                                       ]
                                         },
                          },
                    'nights' => '1',
                    'enddate' => '2011-01-24',
                    'startdate' => '2011-01-23'
                  }
        };


Last edited by pludi; 12-28-2010 at 06:10 AM..
# 2  
Old 12-28-2010
It is hard to tell what is going wrong for you given that you have not shown us any of your source code.

If you actually want people to be able to help you, you need to provide an example XML file and the relevant part of your source code.
# 3  
Old 12-28-2010
This is my code:
Code:
my $results = $res->content;
$xml = new XML::Simple (KeyAttr => [],suppressempty => 1,ForceArray => 
['roomtype']);
$data = $xml->XMLin("$results");

foreach $e (@{$data->{data}->{bb}->{roomtypes}->{roomtype}})
{
  $roomtypename=$e->{roomtypename};
  $rateid=$e->{mealtypes}->{mealtype}->{rateid};
}

I only receive the error when trying to get the value of rateid for the mealtype, if it is more than one, and I don't know how to loop through the mealtypes

Last edited by Scott; 12-28-2010 at 10:43 AM.. Reason: Code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to pull multiple XML tags from the same XML file in Shell.?

I'm searching for the names of a TV show in the XML file I've attached at the end of this post. What I'm trying to do now is pull out/list the data from each of the <SeriesName> tags throughout the document. Currently, I'm only able to get data the first instance of that XML field using the... (9 Replies)
Discussion started by: hungryd
9 Replies

2. Shell Programming and Scripting

Split xml file into multiple xml based on letterID

Hi All, We need to split a large xml into multiple valid xml with same header(2lines) and footer(last line) for N number of letterId. In the example below we have first 2 lines as header and last line as footer.(They need to be in each split xml file) Header: <?xml version="1.0"... (5 Replies)
Discussion started by: vx04
5 Replies

3. Shell Programming and Scripting

Shell Command to compare two xml lines while ignoring xml tags

I've got two different files and want to compare them. File 1 : HTML Code: <response ticketId="944" type="getQueryResults"><status>COMPLETE</status><description>Query results fetched successfully</description><recordSet totalCount="1" type="sms_records"><record... (1 Reply)
Discussion started by: Shaishav Shah
1 Replies

4. Shell Programming and Scripting

How to add the multiple lines of xml tags before a particular xml tag in a file

Hi All, I'm stuck with adding multiple lines(irrespective of line number) to a file before a particular xml tag. Please help me. <A>testing_Location</A> <value>LA</value> <zone>US</zone> <B>Region</B> <value>Russia</value> <zone>Washington</zone> <C>Country</C>... (0 Replies)
Discussion started by: mjavalkar
0 Replies

5. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

6. Shell Programming and Scripting

Simple XML file comparison and merging

Okay, first of all, thanks to everyone who's helped me out before... I appreciate the opportunity to learn. I have two iTunes XML files, and I simply want to compare the contents, then merge. Theoretically, this will allow me to merge two libraries, keeping playlists intact (depending on iTunes'... (4 Replies)
Discussion started by: karlp
4 Replies

7. Shell Programming and Scripting

using XML::simple in shell scripting

CPAN provide xml::simple module which can be used to generate XML files. can i use this module in shell scripting? how? plzz give me an example to generate xml file using this module . you can also use some other module.. BUT SHELL SCRIPTING SHOULD ONLY BE USED (4 Replies)
Discussion started by: cynosure2009
4 Replies

8. Shell Programming and Scripting

Perl - problem with CPAN module XML::Simple

Hi All, I am trying to run the following program #!/usr/bin/perl # use module use XML::Simple; use Data::Dumper; # create object $xml = new XML::Simple; # read XML file $data = $xml->XMLin("dump.xml"); # print output print Dumper($dump); At first i had the error mesage saying... (5 Replies)
Discussion started by: userscript
5 Replies

9. Shell Programming and Scripting

How to remove xml namespace from xml file using shell script?

I have an xml file: <AutoData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Table1> <Data1 10 </Data1> <Data2 20 </Data2> <Data3 40 </Data3> <Table1> </AutoData> and I have to remove the portion xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" only. I tried using sed... (10 Replies)
Discussion started by: Gary1978
10 Replies
Login or Register to Ask a Question