Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: Parsing with XML::Simple

by Mr. Muskrat (Canon)
on Aug 23, 2016 at 18:56 UTC ( #1170247=note: print w/replies, xml ) Need Help??

in reply to Parsing with XML::Simple

You said that you want the value -2225 which is in the MaxCode element but you're looking for it in the ErrorCode element.

Replies are listed 'Best First'.
Re^2: Parsing with XML::Simple
by Anonymous Monk on Aug 23, 2016 at 19:05 UTC
    I just typed the sample code wrong, sorry!
    #!/usr/bin/perl use strict; use warnings; use XML::Simple; use Data::Dumper; use Data::Dump 'pp'; #my $content = $response->decoded_content(); my $content = qq|<?xml version=\'1.0\' encoding=\'UTF-8\'?><soap:Envel +ope xmlns:soap=""> <soap:Header><ais:requestID xmlns:ais="http://com"> {7f000001-47db2420000001569783cdb88136} </ais:requestID> </soap:Header> <soap:Body> <soap:Fault> <faultcode>soap:Server</faultcode> <faultstring> check expression: </faultstring> <faultactor>CheckTwo</faultactor> <detail> <longDescription xmlns="http://com"> Exception occurred </longDescription> <MaxCode xmlns="http://com/Server">-2225</MaxCode> </detail> </soap:Fault> </soap:Body> </soap:Envelope>|; #my $parser = new XML::Simple; my $parser= XML::Simple->new( KeepRoot => 1, KeyAttr => [], ForceArray + => [qw( MaxCode )] ); my $data = $parser->XMLin($content); my $result = $data->{'soap:Body'}->{'soap:Fault'}->{'detail'}->{'MaxCo +de'};


      Okay. I ran this code and noticed that you probably want to start at the top.

      my $result = $data->{'soap:Envelope'}{'soap:Body'}{'soap:Fault'}{detail}{MaxCode}; # removed unnecessary punctuation

      This won't give you the answer you seek but push you in the right direction. I'll also give you a hint... You told it to treat MaxCode as an array.

        Got to work by simplifying the code like this, with one issue:
        ... my $parser = new XML::Simple; my $data = $parser->XMLin($content); my $result = $data->{'soap:Body'}{'soap:Fault'}{'detail'}{'MaxCode'}; print $result->{content};

        The only thing is that once the value of "$result" is empty, I am getting this:
        Use of uninitialized value in string

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1170247]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (10)
As of 2018-06-19 07:40 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (111 votes). Check out past polls.