Hello,
I have been battling with this for two days and I now have gone in so may circles I don't know what's left to try.
I have the following XML file (This is just a small section) which is output from another system:
<?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>
I have used XML::Simple and have reach the point where just to try get anything, I have reduced the code to:
use strict;
use warnings;
my $xmldoc = XMLin("C:\\dsys.xml");
print Dumper($xmldoc);
At this point all is well, but what I'd like is the values in the
<Vendor> tag in a hash with the
vendorUniqueKey as the key and the
name as the value.
I've tried:
my $vendors = "$xmldoc->{'Catalog'}->{'Vendors'}";
Which returns a reference to the hash (I think), but I can'
t seem to find a way to step through the data in the hash. When I try:
my $vendors = "$xmldoc->{'Catalog'}->{'Vendors'}";
foreach my $vendor (@{$vendors->{Vendor}}) {
print $vendor->{name} . "\n";
}
I get
Can't use string ("HASH(0x31d7078)") as a HASH ref while "strict refs" in use and I get similar errors if I try a host of other ways. Clearly I'm lost and don't know where to go from here. I don't even know if the data I need is in the hash or if I've completely messed it up.
Any help would be appreciated.
Regards,
Smaug.
Peddle faster monkeys!! I need more power!!
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.