Go Back   CodingForums.com > :: Client side development > XML

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-29-2008, 10:00 PM   PM User | #1
nine72
New Coder

 
Join Date: Aug 2008
Location: Addison Tx
Posts: 20
Thanks: 6
Thanked 0 Times in 0 Posts
nine72 is an unknown quantity at this point
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!
nine72 is offline   Reply With Quote
Old 09-30-2008, 03:06 AM   PM User | #2
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
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
oesxyl is offline   Reply With Quote
Old 09-30-2008, 03:15 AM   PM User | #3
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
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
oesxyl is offline   Reply With Quote
Old 09-30-2008, 03:21 PM   PM User | #4
nine72
New Coder

 
Join Date: Aug 2008
Location: Addison Tx
Posts: 20
Thanks: 6
Thanked 0 Times in 0 Posts
nine72 is an unknown quantity at this point
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…
nine72 is offline   Reply With Quote
Old 09-30-2008, 04:11 PM   PM User | #5
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
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
oesxyl is offline   Reply With Quote
Users who have thanked oesxyl for this post:
nine72 (09-30-2008)
Old 09-30-2008, 06:18 PM   PM User | #6
nine72
New Coder

 
Join Date: Aug 2008
Location: Addison Tx
Posts: 20
Thanks: 6
Thanked 0 Times in 0 Posts
nine72 is an unknown quantity at this point
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....
nine72 is offline   Reply With Quote
Old 09-30-2008, 08:42 PM   PM User | #7
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
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
oesxyl is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:51 AM.


Advertisement
Log in to turn off these ads.