in reply to Dereferencing a hashref from XML::Simple

I'd suggest you use XML::TreeBuilder:

use warnings; use strict; use XML::TreeBuilder; my $xml =q(<?xml version="1.0"?> <response> <files> <file file_url="http://server.domain/file1.exe"> file1.exe </file> <file file_url="http://server.domain/file2.zip"> file2.zip </file> </files> </response> ); my $tree = XML::TreeBuilder->new (); $tree->parse ($xml); my @fileElts = $tree->find ('file'); my %file_url; $file_url{$_->attr ('file_url')} = $_->as_text () for @fileElts; print "$_: $file_url{$_}\n" for keys %file_url;

Prints:

http://server.domain/file2.zip: file2.zip http://server.domain/file1.exe: file1.exe

DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^2: Dereferencing a hashref from XML::Simple
by helgi (Hermit) on Jul 28, 2006 at 11:30 UTC
    Thanks, Grandfather.

    It's strange, but your code returns almost exactly the same error as the XML::Simple code above:

    not well-formed (invalid token) at line 4, column 49, byte 93 at /usr/ +lib/perl5/vendor_perl/5.8.6/i386-linux-thread-multi/XML/Parser.pm lin +e 187
    This happens on Windows (Activeperl) and two different Linux systems. Any idea what's going on?


    --
    Regards,
    Helgi Briem
    hbriem AT f-prot DOT com

      It works fine here as you can see from the sample output. I'd guess a bad character in the XML string. Try overwriting it with your original sample data or at least delete all the line ends in your editor and replace them with new ones.


      DWIM is Perl's answer to Gödel
Re^2: Dereferencing a hashref from XML::Simple
by helgi (Hermit) on Jul 28, 2006 at 11:35 UTC
    Sorry, I seem to have made a mistake. Your code works very well. Thank you very much for the help, Grandfather.


    --
    Regards,
    Helgi Briem
    hbriem AT f-prot DOT com