Hi, I have this massive (4000 plus lines of code) generating a huge XML string (500 to 1000 tags). My back end system reply’s to me via an xml response. The response can contain ALL of my xml tags if there is an error with the input.
If everything is good then I get a very short xml response…
I need to take and parse the return string and print the results out to ether a complete or failed page that is in php.
Here is a sample of the error response…
PHP Code:
<Response>
<Transaction>NewAdd</Transaction>
<SessionId>46A644041DD3EDC696B68CD503AABCAB</SessionId>
<ResponseText>Failed</ResponseText>
<ErrCode>ERROR_BL_00023</ErrCode>
<ErrMsg>
Location:
<device_category>HANDHELD</device_category>
<device_name>BLAKBERRY</device_name>
<device_model>82XX</device_model>
<device_application>FINANCEING</device_application>
<device_gateway>NODE42</device_gateway>
<device_comm_format>LANDLINE</device_comm_format>
<device_mode>W</device_mode>
<device_dial_up>N</device_dial_up>
<device_flag>Y</device_flag>
Description: can NOT find any udid from our database system.
Solution: please check information listed above.
</ErrMsg>
</Response>
This is the routine that I am working with to handle the response….
PHP Code:
//Send XML
$xmlResponse = sendXMLString($xmlString);
//Check for curl error
if ( $xmlResponse == "" )
{
header("Location: " . $GatewaySettings['CommitFailed'] . "?gateway_error=") . rawurlencode("Error Loading KIOSK. Please try again.");
}
else
{
// Parse XML response
$xml_parser = xml_parser_create();
// set to not change to uppercase
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 0);
// ignore white space
xml_parser_set_option($xml_parser, XML_OPTION_SKIP_WHITE, 1);
// puts values in an array of xml tags (vals)
xml_parse_into_struct($xml_parser, $xmlResponse, $vals, $index);
xml_parser_free($xml_parser);
$retTransaction = "";
$retSessionId = "";
$retErrCode = "";
$retErrMsg = "";
$retResponce = "";
$numTags = $index[Response][1]; // number of tags including Response
$numTags = 6;
for ($x=0; $x<$numTags; $x++)
{
$key = $vals[$x][tag];
switch ($key)
{
case "Transaction":
$retTransaction = $vals[$x][value];
break;
case "Transaction ID":
$retSessionId = $vals[$x][value];
break;
case "Responce":
$retResponce = $vals[$x][value];
break;
case "Error Code":
$retErrCode = $vals[$x][value];
break;
case "Error Message":
$retErrMsg = $vals[$x][value];
break; //there can be as manay as 1000 "tags" in the Error Message.
default:
// if other message could be error
$retErrMsg = $vals[$x][value];
break;
} // end switch
} // end for loop
if ( $retResponce == "SUCCEED")
{
header("Location: " . $GatewaySettings[‘LoadedPage'] . "?Responce=" . rawurlencode($retResponce) . "&ApprovalCode=" . rawurlencode($retResponce));
}
else
{
//Function that takes retActionCode -> String based on code
header("Location: " . $GatewaySettings['FailedPage'] . "?gateway_error=" . rawurlencode($retResponce) . "&ErrorMsg=" . rawurlencode($retErrMsg));
}
}
}
else
{
header("Location: " . $GatewaySettings['FailedPage] . "?gateway_error=" . rawurlencode($retErrMsg));
}
Any ideas, suggestions, samples, or edits are welcome…
Thanks!