Jump to content

Working with XML results from a URL


Go to solution Solved by boompa,

Recommended Posts

I need to get the values from an XML result from a URL.

 

Here is what I have tried to work out after reading tutorials, but am stumped as to going further:

<?
$xmlstr = file_get_contents("https://www.site.com/checksession.asp?clientid=3915&password=byuc0913&wait=60&sessionid=8863AC8A23498DDC27993EF9F6330C50B2B4FDFE");

$reply = new SimpleXMLElement($xmlstr);

$reponse = "";
$completed = "";
$last4 = "";
$approvedamt = "";
?>

Here is the output of the URL in file_get_contents:

<?xml version="1.0" encoding="utf-8"?>
<reply>
  <response>Success</response> 
  <responsecode>0</responsecode> 
  <description>OK</description> 
  <responseurl>/soft/checksession.asp</responseurl> 
  <datablock>
		<sessionid>8863AC8A23498DDC27993EF9F6330C50B2B4FDFE</sessionid>
		<completed>yes</completed>
		<approved>Y</approved>
		<declinecount>0</declinecount>
		<gateid>76479220</gateid>
		<transtype>SALE</transtype>
		<authcode>191330</authcode>
		<avsreply>U</avsreply>
		<cvv2reply> </cvv2reply>
		<declinestr>OK</declinestr>
		<cardtype>V</cardtype>
		<cardname>Visa</cardname>
		<first6>403491</first6>
		<last4>4971</last4>
		<keyed>No</keyed>
		<expmonth>07</expmonth>
		<expyear>16</expyear>
		<approvedamt>9.67</approvedamt>
		<tip>0</tip>
		<bal></bal>
		<invoiceno>22513</invoiceno>
		<corporatecardindicator></corporatecardindicator>
		<processor_token></processor_token>
</datablock>
</reply>

Any help would be GREATLY appreciated! :)

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/279640-working-with-xml-results-from-a-url/
Share on other sites

<?

$xmlstr = file_get_contents("https://www.site.com/checksession.asp?clientid=3915&password=byuc0913&wait=60&sessionid=8863AC8A23498DDC27993EF9F6330C50B2B4FDFE");

$reply = new SimpleXMLElement($xmlstr);

echo $reply->response;
echo $reply->datablock->completed;

?>

Gave this as output:


Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 34: parser error : Opening and ending tag mismatch: meta line 15 and head in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: </head> in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 37: parser error : Entity 'nbsp' not defined in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]:  	</div> in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 117: parser error : Entity 'nbsp' not defined in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]:  	 </div> in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 141: parser error : Opening and ending tag mismatch: br line 140 and div in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: </div>	 </div> in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 141: parser error : Opening and ending tag mismatch: br line 140 and div in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: </div>	 </div> in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 195: parser error : Opening and ending tag mismatch: div line 120 and body in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: </body> in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 196: parser error : Opening and ending tag mismatch: div line 119 and html in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: </html> in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 197: parser error : Premature end of data in tag body line 35 in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 197: parser error : Premature end of data in tag head line 3 in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 197: parser error : Premature end of data in tag html line 2 in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5

Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /home/tdh/public_html/network/esid/SCD_checksession.php:5 Stack trace: #0 /home/tdh/public_html/network/esid/SCD_checksession.php(5): SimpleXMLElement->__construct('??<!DOCTYPE htm...') #1 {main} thrown in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.