Jump to content

XML Error


waddledoo

Recommended Posts

I am trying to get an XML file from a URL, but am instead getting errors.

The code worked perfectly when executed on my own computer through a localhost server, but when executed through my webhost's server I get the errors.

I am running PHP 5.3.8, and my webhost is running PHP 5.2.17, so I am assuming this may be an error between versions.

 

$ch = curl_init($url);

// Set the options for this request//This section returned a function not found error when activated on the webhost's server
/*curl_setopt_array($ch, array(
	CURLOPT_FOLLOWLOCATION => true, // Yes, we want to follow a redirect
	CURLOPT_RETURNTRANSFER => true, // Yes, we want that curl_exec returns the fetched data
	CURLOPT_SSL_VERIFYPEER => false, // Do not verify the SSL certificate
));*/

// Fetch the data from the URL
$data = curl_exec($ch);

// Close the connection
curl_close($ch);


// Return a new SimpleXMLElement based upon the received data //The following is line 27 in the code
if (!$xml = new SimpleXMLElement($data))
	echo 'FAIL.';

 

Errors:

Warning: Entity: line 1: parser error : Start tag expected, '<' not found in /home/(etc etc) on line 27

 

Warning: 1 in /home/(etc etc) on line 27

 

Warning: ^ in /home/(etc etc) on line 27

 

Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /home/(etc etc):27 Stack trace: #0 /home/(etc etc)(27): SimpleXMLElement->__construct('1') #1 /home/(etc etc)(71): retrieveXMLdata() #2 {main} thrown in /home/(etc etc) on line 27

Link to comment
Share on other sites

The URL contains the following:

 

<api>
<currentTime>2011-12-12 21:21:57</currentTime>
<result>
<rowset name="entries" key="refID" columns="date,refID,refTypeID,ownerName1,ownerID1,ownerName2,ownerID2,argName1,argID1,amount,balance,reason">
<row date="####-##-## ##:##:##" refID="#####" refTypeID="#####" ownerName1="#####" ownerID1="#####" ownerName2="#####" ownerID2="#####" argName1="#####" argID1="#####" amount="#####" balance="#####" reason="#####"/>
<row date="####-##-## ##:##:##" refID="#####" refTypeID="#####" ownerName1="#####" ownerID1="#####" ownerName2="#####" ownerID2="#####" argName1="#####" argID1="#####" amount="#####" balance="#####" reason="#####"/>
<row date="####-##-## ##:##:##" refID="#####" refTypeID="#####" ownerName1="#####" ownerID1="#####" ownerName2="#####" ownerID2="#####" argName1="#####" argID1="#####" amount="#####" balance="#####" reason="#####"/>
(etc etc...)
</rowset>
</result>
<cachedUntil>2011-12-12 21:48:57</cachedUntil>
</api>

Link to comment
Share on other sites

curl_setopt($ch,CURLOPT_FOLLOWLOCATION => true);
curl_setopt($ch,CURLOPT_RETURNTRANSFER => true);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER => false);

 

To that effect?

 

EDIT:

I get the error

Parse error: parse error, unexpected T_DOUBLE_ARROW

 

With the code. I changed the => to = with no effect. How do I properly use this function then?

 

Second EDIT:

I replaced the => with , (commas)

ex/

curl_setopt($ch,CURLOPT_SSL_VERIFYPEER ,false);

 

And I no longer get errors. My code still seems to not be running properly later in the program, and I am debugging now to find what is wrong.

However, this particular post seems to be solved.

Link to comment
Share on other sites

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.