In my experience, XML::Simple makes dealing with very simple XML simple but it makes dealing with more complex XML quite difficult. Had you spent two days learning one of the alternatives (I use XML::LibXML almost exclusively these days, but there are other very capable modules that give you good control over both parsing and generation of XML files) you could probably have solved your problem and learned a more powerful tool for future work.
In summary, my suggestion is to use XML::Simple if it does what you need by default or you can tweak it in a few minutes. Otherwise, invest in learning a more general/powerful tool.
Update:
As an example of one way to get your hash with XML::LibXML:
use strict;
use warnings;
use XML::LibXML;
use Data::Dumper;
my $xml = do { local $/; <DATA> };
my $dom = XML::LibXML->load_xml(string => $xml);
my %vendors = map {
$_->getAttribute('vendorUniqueKey') => $_->getAttribute('name')
} @{$dom->getElementsByTagName('Vendor')};
print Dumper(\%vendors);
__DATA__
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Import format="3.0" fileId="54630000-3141-1404-4310-7F0000014030" fil
+eCreationDateTime="2012-07-23T06:04:31.415" catalogSource="TLCMz">
<Catalog>
<Vendors>
<Vendor name="Allen Systems" vendorUniqueKey="ALLENGRP"/>
<Vendor name="Aonix North America" vendorUniqueKey="AONIX"/>
<Vendor name="Beta Systems Software" vendorUniqueKey="BETASY
+S"/>
<Vendor name="BMC Software" vendorUniqueKey="BMC"/>
</Vendors>
</Catalog>
</Import>
gives
$VAR1 = {
'BETASYS' => 'Beta Systems Software',
'BMC' => 'BMC Software',
'ALLENGRP' => 'Allen Systems',
'AONIX' => 'Aonix North America'
};
That's simple enough. The problem is, reading all the XML::LibXML docs (there are many) to find out how to do this isn't so simple.
-
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.
|