Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Aug 2008
    Location
    Addison Tx
    Posts
    20
    Thanks
    6
    Thanked 0 Times in 0 Posts

    How to parse xml response not sure if right forum...

    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>
                
    Descriptioncan 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_parserXML_OPTION_CASE_FOLDING0);
                
    // ignore white space
                
    xml_parser_set_option($xml_parserXML_OPTION_SKIP_WHITE1);
                
    // 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!

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    this is not valid xml:
    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>
    If I understand the problem you could use xslt to process the xml and build the page you want. Look into the php manual of DOM extension.

    best regards

  • #3
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    I just see a typo:
    PHP Code:
                if ( $retResponce == "SUCCEED")
                {
                    
    header("Location: " $GatewaySettings[&#8216;LoadedPage'] . "?Responce=" . rawurlencode($retResponce) . "&ApprovalCode=" . rawurlencode($retResponce)); 
    must be:
    PHP Code:
                if ( $retResponce == "SUCCEED")
                {
                    
    header("Location: " $GatewaySettings['LoadedPage'] . "?Responce=" rawurlencode($retResponce) . "&ApprovalCode=" rawurlencode($retResponce)); 
    best regards

  • #4
    New Coder
    Join Date
    Aug 2008
    Location
    Addison Tx
    Posts
    20
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Thanks for the info,
    I have given the not valid part to the person handling the response part.
    Fixed the typo this morning but it is not working as needed.

    For reasons that have not been explained to me...and they never are explained to me….
    I can not use DOM or SAX to parse it out….

    I have a set of pages where this is working, it is an old form for credit card transactions.
    I uses the same methods to pass and receive, that parses the response just fine and sends to the correct page. I was attempting to build off that process. I guess I will have to dig a bit deeper…

  • #5
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by nine72 View Post
    Thanks for the info,
    I have given the not valid part to the person handling the response part.
    Fixed the typo this morning but it is not working as needed.

    For reasons that have not been explained to me...and they never are explained to me….
    I can not use DOM or SAX to parse it out….

    I have a set of pages where this is working, it is an old form for credit card transactions.
    I uses the same methods to pass and receive, that parses the response just fine and sends to the correct page. I was attempting to build off that process. I guess I will have to dig a bit deeper…
    try to check if xml response is not truncated, this could be an effect of using GET method instead of POST.

    best regards

  • Users who have thanked oesxyl for this post:

    nine72 (09-30-2008)

  • #6
    New Coder
    Join Date
    Aug 2008
    Location
    Addison Tx
    Posts
    20
    Thanks
    6
    Thanked 0 Times in 0 Posts
    badabing-o
    that was it, I had them make a small change and it is all working now..

    Thanks Oesxyl!

    now how to close this topic....

  • #7
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by nine72 View Post
    badabing-o
    that was it, I had them make a small change and it is all working now..

    Thanks Oesxyl!

    now how to close this topic....
    I'm glad that is solved,
    To close the thread, you can edit it and add a prefix "resolved",

    best regards


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •