Not an ARRAY reference



I am reading an XML file in perl and looping through the items and
manipulating data. If I have 2 or more 'menuitems' in my xml file it
works ok. if i only have one like the code below I get "Not an ARRAY
reference" at the foreach line - any ideas why?

$create_menu = new XML::Simple (KeyAttr=>[]);

$data = $create_menu->XMLin($xml_file);

foreach $e (@{$data->{menuitem}}){
......
}


xml is
<?xml version='1.0'?>
<menu>
<menuitem>
<node>1</node>
<parent>1</parent>
<sibling>1</sibling>
<submenu>0</submenu>
<subsubmenu>0</subsubmenu>
<label>ramooooooooooon</label>
<link>topic1.xml</link>
</menuitem>
</menu>

.



Relevant Pages

  • Re: Not an ARRAY reference
    ... If I have 2 or more 'menuitems' in my xml file it ... if i only have one like the code below I get "Not an ARRAY ... > reference" at the foreach line - any ideas why? ...
    (comp.lang.perl.misc)
  • Re: Not an ARRAY reference
    ... > I am reading an XML file in perl and looping through the items and ... > manipulating data. ... If I have 2 or more 'menuitems' in my xml file it ...
    (comp.lang.perl.misc)
  • xslt to HTML Transform question
    ... I have an xml file similar to: ... What I am trying to achieve is a table that takes every four menuitems ... I cannot figure out how to loop four and place them in a tag ... ~Adam dR. ...
    (comp.text.xml)
  • Looping through nested XML
    ... I am writing an XML menu structure. ... <MenuItems> ... I have read the xml file into a dataset using the following code and I ... I dont know how to access or create the relationship. ...
    (microsoft.public.dotnet.xml)
  • Holding and changing a variable in XSLT
    ... This is a snippet of my XSLT ... I am looping an XML file. ...
    (comp.text.xml)