The reason i used the keyattr in my previous reply was due to a strange quirk within XML::Simple. Consider this example:
use XML::Simple; use Data::Dumper; my $xml = XMLin(\*DATA); print Dumper $xml; __DATA__ <documents> <document> <stayonhost>1</stayonhost> <staybelow>1</staybelow> <maxdepth>2</maxdepth> <name>Swedish Foo</name> <home_url>http://www.foo.se/bar/</home_url> <category>International</category> </document> <document> <stayonhost>0</stayonhost> <staybelow>0</staybelow> <maxdepth>3</maxdepth> <name>Swedish Bar</name> <home_url>http://www.bar.se/baz/</home_url> <category>National</category> </document> </documents>
and it's output:
$VAR1 = {
  'document' => {
    'Swedish Foo' => {
      'category' => 'International',
      'maxdepth' => '2',
      'stayonhost' => '1',
      'staybelow' => '1',
      'home_url' => 'http://www.foo.se/bar/'
    },
    'Swedish Bar' => {
      'category' => 'National',
      'maxdepth' => '3',
      'stayonhost' => '0',
      'staybelow' => '0',
      'home_url' => 'http://www.bar.se/baz/'
    }
  }
};
What happened to the name element? I don't know for sure, but i am guessing that XML::Simple treats elements named name differently.* So, i read some docs, figured that keyattr might fix the problem and it did. But first i tried forcearray, which didn't fix the problem. I didn't think it would, but i didn't have a spare chicken to sacrifice at the time. ;) In case you are wondering ... forcearray is useful for keeping XML elements in order, remember that hashes lose order. forcearray is also useful for keeping your code consistent - you can always (99.99%?) expect an array, no guessing with ref needed.

I guess my point is that XML::Simple can handle tasks that are really beyond its scope, and you should be wary of that. It's great for getting stuff done quick, but you probably should pick a more industrial strength module for serious production code - like XML::Twig.

* yep ... here's what the docs say:
   The default value for 'keyattr' is ['name', 'key',
   'id'].  Setting this option to an empty list will
   disable the array folding feature.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to (jeffa) Re: XML::Complicated by jeffa
in thread XML::Complicated by hacker

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.