#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Posts
    72
    Rep Power
    10

    XML::Simple trying to ouput


    I have written a little script here that grabs xml data and tries to print one part of an element but im missing / doing something wrong here... i keep getting the error "Not a HASH reference at ./test2 line 25." Yet i do a data dump and my code appears to look fine... am i missing something?

    here is my little code

    Code:
    #!/usr/bin/perl
    
    use strict;
    use warnings;
    use HTTP::Request::Common qw(POST);
    use LWP::UserAgent;
    use XML::Simple;
    use Data::Dumper qw(Dumper);
    
    our $apiroot = 'http://api.eve-online.com';
    our $ua = LWP::UserAgent->new;
    
    my $req = POST $apiroot.'/eve/SkillTree.xml.aspx';
    my $res = $ua->request($req);
    unless ($res->is_success) {
       die "Error: " . $res->status_line . "\n";
    }
    my $text = $res->decoded_content;
    #print Dumper($text), "\n\n";
    my $xml = XMLin($text, KeepRoot => 1, KeyAttr=> {rowset => '+name', row => '+typeID'});
    #print Dumper($xml), "\n\n";
    
    foreach my $id (keys %{ $xml->{eveapi}{result}{rowset}{row}{rowset}{row}}) {
      print $xml->{eveapi}{result}{rowset}{row}{rowset}{row}{$id}{typeName} . "\n";
    }
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Posts
    72
    Rep Power
    10
    ive got it working somewhat, its not outputting all the info that the xml has. Anyone have any idea why? it seems to be with the row=> '+groupID' im thinking but removing that breaks it completely.


    Code:
    #!/usr/bin/perl
    
    use strict;
    use warnings;
    use HTTP::Request::Common qw(POST);
    use LWP::UserAgent;
    use XML::Simple;
    use Data::Dumper qw(Dumper);
    
    our $apiroot = 'http://api.eve-online.com';
    our $ua = LWP::UserAgent->new;
    
    my $req = POST $apiroot.'/eve/SkillTree.xml.aspx';
    my $res = $ua->request($req);
    unless ($res->is_success) {
       die "Error: " . $res->status_line . "\n";
    }
    my $text = $res->decoded_content;
    #print $text;
    my $xml = XMLin($text, KeepRoot => 1, KeyAttr => {rowset => '+name', row => '+groupID'}, ForceArray => [ 'row' ]);
    $xml->{eveapi}{$xml->{eveapi}{result}{rowset}{name}} = $xml->{eveapi}{result}{rowset}; delete $xml->{eveapi}{result};
    foreach my $id (keys %{ $xml->{eveapi}{skillGroups}{row} }) {
      foreach my $id2 (keys %{ $xml->{eveapi}{skillGroups}{row}{$id}{rowset}{row} }) {
        print $xml->{eveapi}{skillGroups}{row}{$id}{rowset}{row}{$id2}{typeName} . "\n";
      }
    }

IMN logo majestic logo threadwatch logo seochat tools logo