Page 1 of 1

Parsing a Soap Response

Posted: Fri Jul 12, 2013 1:01 pm
by Steve Kucera
I'm still pretty new to xml and SOAP and need assistance parsing the following data ( from Dumper($data) ):

$VAR1 = {
'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
'soap:Body' => {
'PurchasePinResponse' => {
'xmlns' => 'http://www.pininteract.com',
'orderResponse' => {
'xmlns' => 'urn:pininteract.com',
'invoice' => {
'invoiceAmount' => '45.000',
'faceValueAmount' => '50.00',
'cards' => {
'card' => {
'skuId' => '199',
'pins' => {
'pin' => {
'pinNumber' => '50489898515256',
'controlNumber' => '111111111111'
}
},
'name' => 'Simple Mobile',
'faceValue' => '50.00'
}
},
'invoiceNumber' => '4515563',
'transactionDateTime' => '2013-07-12T11:30:07.17'
},
'responseCode' => '000',
'version' => '1.0'
}
}
},
'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema',
'xmlns:soap' => 'http://schemas.xmlsoap.org/soap/envelope/'
};

I need to extract the PIN number to store it in a database.

I know the syntax should be something along the lines of:

$something->{more_something}->{more_something}

I am in a pinch and not getting it done. If anyone can help me I would appreciate it. Once I see it I will be able to see how you arrived at the solution.

Thanks.

Re: Parsing a Soap Response

Posted: Mon Jul 15, 2013 9:14 pm
by toast0
it's hard to tell without indentation; but it looks like you want
$VAR1->{'soap:Body'}{'PurchasePinResponse'}{'orderResponse'}{'invoice'}{'cards'}{'card'}{'pins'}{'pin'}{'pinNumber'}

Yay SOAP! You need to be a bit more careful about the xml parsing if cards or pins could ever have more than one card or pin (There are ways to tell the perl XML parser what's an array and what isn't...)