What's wrong with XML::Simple?

  1. XMLin( "file") looks pretty concise to me. Even when using the OO mode it is still pretty short: my $config= XML::Simple->new( forcearray => 1);
  2. I don't know what you mean by Integrate-able with perl OO, you get a clean data structure, what else would you want?
  3. the forcearray option makes XML::Simple behave sanely I believe.
  4. .

BTW I think your XML structure is not quite optimal, you repeat the X and Y when I believe they should mark a container object (see below).

Finally I have added a simplify method to XML::Twig that should be more or less equivalent to XMLin. It is very much in alpha state at the moment, but if you grab the development version of XML::Twig from xmltwig.com you can try the code below.

So here is the result with XML::Simple and with XML::Twig, output using YAML, both for your XML and for an updated version:

#!/usr/bin/perl -w use XML::Simple; use XML::Twig; use YAML; $/="\n\n"; my $xml= <DATA>; print "Original Version:\n"; print "Loaded using XML::Simple: \n", Dump( XMLin( $xml, forcearray => 1, keyattr => [])); print "Loaded using XML::Twig: \n", Dump( XML::Twig->new->parse( $xml)->simplify( keyattr => [])); $xml=<DATA>; print "Original Version:\n"; print "Loaded using XML::Simple: \n", Dump( XMLin( $xml, forcearray => 1, keyattr => [ 'name', 'type' +])); print "Loaded using XML::Twig: \n", Dump( XML::Twig->new->parse( $xml)->simplify( keyattr => [ 'nam +e', 'type'])); __DATA__ <?xml version='1.0' standalone='yes'?> <config name="MyConfig"> <blah name="X" type="T1"> A </blah> <blah name="X" type="T2"> B </blah> <blah name="Y" type="T3"> C </blah> <blah name="Y" type="T4"> D </blah> <l1 foo1="bar1"> <l2 foo2="bar2"> <l3> Sometext </l3> </l2> </l1> </config> <?xml version='1.0' standalone='yes'?> <config name="MyConfig"> <blah name="X"> <foo type="T1"> A </foo> <foo type="T2"> B </foo> </blah> <blah name="Y"> <foo type="T3"> C </foo> <foo type="T4"> D </foo> </blah> <l1 foo1="bar1"> <l2 foo2="bar2"> <l3> Sometext </l3> </l2> </l1> </config>

In reply to Re: Practical suggestion for accessing configuration data stored in XML format by mirod
in thread Practical suggestion for accessing configuration data stored in XML format by fuzzycow

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.