What's wrong with XML::Simple?
- 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);
- I don't know what you mean by Integrate-able with perl OO, you get a clean data structure, what else would you want?
- the forcearray option makes XML::Simple behave sanely I believe.
.
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>
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.