Thread

Posted on Thu Mar 6 19:04:08 2008 by mj
Need Help with ForceArray
I thought I understood how things worked, but now...
The command I'm using to parse:
XMLin($menufile, forcearray=>[ 'item', 'command', 'exec','menu'],keyattr=>['name'], suppressempty=> +undef);
From what I understood, I am "folding" 'item' into an array, but for some reason it's not always folding.
Thanks in advance.
Michele
Here's an example of my xml that's not working:
<opt>
   <menu name="MainMenu">
      <label > Main Menu <\label>
      <item > type="command">
         <exec> /path/to/foo <\exec>
      <\item>
      <item > type="submenu">
         <name> AnotherMenu <\name>
      <\item>
   <\menu>
   <menu name="AnotherMenu">
      <label > Another Menu <\label>
      <item > type="submenu">
         <name> YetAnotherMenu <\name>
      <\item>
   <\menu>
<\opt>
Direct Responses: 7282 | Write a response
Posted on Thu Mar 6 21:38:45 2008 by grantm in response to 7280
Re: Need Help with ForceArray

XML::Simple represents one XML element as a hash. If you have two elements with the same XML tag name then they will be represented as an array of hashes. 'Folding' refers to transforming the array of hashes into a hash of hashes where the hash key is the value of a common attribute. In your example XML (which is badly malformed), the item elements do not all have a common 'name' - some have name and some have exec.

I suggest you read this article and if you have further problems, ask on PerlMonks rather than on this site.

http://www.perlmonks.org/index.pl?node_id=218480

Write a response