XML Parsing
| From: | Michael Conley | Date: | Mon, 30 Apr 2001 22:21:16 +0000 |
| Subject: | XML Parsing | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-50925@lists.php.net to get a copy of this message | ||
I am posting information to a credit card processing server. This is done
over HTTPS (with cURL) and seems to work fine. I get the response that I
want from the server, which consists of an XML doc with about 20 tags and
their corresponding values. I have gone through the mailing list and
manuals, yet I still can't seem to figure out how to get each piece of the
XML doc into their own variables.
Here is the code I am using:
$server = "https://www.creditcard.com";
$path = "xmlhttps/xtrans.asp";
$ch = curl_init();
$requestedurl = "$server" . "/$path";
curl_setopt($ch, CURLOPT_URL, "$requestedurl");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "$xmlstring");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,0);
curl_close ($ch);
This replies (as it should) with an XML doc like this:
<RESPONSE><SERVICE>CC</SERVICE><SERVICE_TYPE>DEBIT</SERVICE_TYPE><SERVICE_SU
BTYPE>AUTH</SERVICE_SUBTYPE><SERVICE_FORMAT>1010</SERVICE_FORMAT><TERMINAL_I
D>PC-9999</TERMINAL_ID><PIN>1234</PIN><TRANSACTION_INDICATOR>7</TRANSACTION_
INDICATOR><AMOUNT>5</AMOUNT><ACCOUNT_NUMBER>1234</ACCOUNT_NUMBER><EXPIRATION
>1202</EXPIRATION><FIRST_NAME>Michael</FIRST_NAME><LAST_NAME>Conley</LAST_NA
ME><ADDRESS>PO BOX
59</ADDRESS><CITY>Auburn</CITY><STATE>CA</STATE><POSTAL_CODE>95604</POSTAL_C
ODE><COUNTRY>USA</COUNTRY><PHONE></PHONE><OPERATOR>Somebody</OPERATOR><CURRE
NCY_CODE>840</CURRENCY_CODE><TERMINAL_ID></TERMINAL_ID><USER_DATA_0></USER_D
ATA_0><USER_DATA_1></USER_DATA_1><USER_DATA_2></USER_DATA_2><USER_DATA_3></U
SER_DATA_3><USER_DATA_4></USER_DATA_4><USER_DATA_5></USER_DATA_5><USER_DATA_
6></USER_DATA_6><USER_DATA_7></USER_DATA_7><USER_DATA_8></USER_DATA_8><USER_
DATA_9></USER_DATA_9><VERBOSE_RESPONSE></VERBOSE_RESPONSE><SERVICE_PROVIDER>
10</SERVICE_PROVIDER><TRANSACTION_ID>03509KQEGVHMGED4</TRANSACTION_ID><LOCAL
_TIME>172823</LOCAL_TIME><LOCAL_DATE>04302001</LOCAL_DATE><EXCHANGE_RATE>1</
EXCHANGE_RATE><MRC>00</MRC><ARC>00</ARC><RESPONSE_TEXT>NO
MATCH</RESPONSE_TEXT><APPROVAL_CODE>VITAL6</APPROVAL_CODE><AVS_RESPONSE>N</A
VS_RESPONSE><COMMERCIAL_RESPONSE>0</COMMERCIAL_RESPONSE></RESPONSE>
What I need to do now is get certain parts of the return string. How do I
assign the value in the <APPROVAL_CODE> tags to the variable $approvalcode?
I also need to get several other parts of the XML string assigned to
variables so that I can use them elsewhere. I can't seem to figure out how
to do this. I know that I need to change the "CURLOPT_RETURNTRANSFER" to
"1" to allow the information to be placed somewhere other than the screen
for processing, but after that I am not sure how to do this. I have gone
through the mailing lists and through the docs online, but I'm having no
luck.
Any help is appreciated.