Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: XML SOAP Response

by psini (Deacon)
on Jul 31, 2008 at 17:30 UTC ( #701479=note: print w/replies, xml ) Need Help??


in reply to XML SOAP Response

Try adding this at the end of your program.

my @vehicles; foreach (@{$data->{Vehicles}->{Vehicle}}) { my %vehicle; $vehicle{vin}=$_->{vin}; foreach(@{$_->{VehicleAttributes}->{VehicleAttribute}}) { $vehicle{$_->{type}}=$_->{value}; } push(@vehicles,\%vehicle); } print Dumper(\@vehicles);

Updated: corrected several errors, now it works. You have to replace the initialization of $xml with

my $xml = new XML::Simple( ForceArray => ["Vehicle"]);

to force the "Vehicle" tag in your XML to became an array in the generated tree.

Rule One: "Do not act incautiously when confronting a little bald wrinkly smiling man."

Replies are listed 'Best First'.
Re^2: XML SOAP Response
by mitchismoney (Initiate) on Jul 31, 2008 at 17:46 UTC
    Adding the code changed the output to:
    $VAR1 = [];
    Is it a matter of double parsing the file? Or is this were XML::Twig comes in? I've only written some pretty basic Perl so bare with me as I try to learn/understand. I greatly appreciate it!

      Probably just a couple of typos:

      (1) print Dumper(\@vehicles); # plural (2) push(@vehicles,\%vehicle); # hashref (3) $vehicle{$_->{type}}=$_->{value}; # not veihcle

        Three typos in nine lines of code are a bit too many... so I debugged it and found two more errors.

        I said that it was untested, but I'm ashamed for putting so many errors in so little code.

        Rule One: "Do not act incautiously when confronting a little bald wrinkly smiling man."

Re^2: XML SOAP Response
by psini (Deacon) on Jul 31, 2008 at 17:49 UTC

    No, it's a matter of untested code too complex to work at first go. Give me five minutes and I'll try to debug it

    Rule One: "Do not act incautiously when confronting a little bald wrinkly smiling man."

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://701479]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2023-01-27 02:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?