1,105,232 Community Members

curl get xml problem

Member Avatar
mehnihma
Posting Whiz in Training
239 posts since Oct 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi
I have problem getting XML file with curl.
I get empty XML and error:

Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "1" in /home2/public_html/xmlupdate.php on line 62
xml 1 not loaded.

the code for curl:

    $ch =curl_init();
    curl_setopt($ch, CURLOPT_URL,$xml_url_1);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
    curl_setopt($ch, CURLOPT_CAINFO, realpath("certs/ca.pem"));
    curl_setopt ($ch, CURLOPT_SSLCERT, realpath("certs/client.pem"));
    curl_setopt($ch, CURLOPT_SSLKEY, realpath("certs/key.pem"));
    curl_setopt($ch, CURLOPT_SSLKEYPASSWD, "2255"); 
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)');
    $xml_url = curl_exec ($ch);
    echo curl_error($ch);
    curl_close ($ch);

    $xml = simplexml_load_file(utf8_encode($xml_url), 'SimpleXMLElement', LIBXML_NOCDATA);

When I acces XML with web broser it works, there is something wrong in my curl code.

Any ideas?

Thanks

Member Avatar
pritaeas
mod_pritaeas
11,295 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,832 [?]
Skill Endorsements: 155 [?]
Moderator
Featured
Sponsor
 
1
 

If you echo $xml_url is it a valid XML document?

Member Avatar
cereal
Posting Virtuoso
1,710 posts since Aug 2007
Reputation Points: 461 [?]
Q&As Helped to Solve: 345 [?]
Skill Endorsements: 44 [?]
 
1
 

Add CURLOPT_RETURNTRANSFER:

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

And try simplexml_load_string here:

$xml = simplexml_load_file(utf8_encode($xml_url), 'SimpleXMLElement', LIBXML_NOCDATA);

bye!

Member Avatar
mehnihma
Posting Whiz in Training
239 posts since Oct 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi I have added it, and I get:

Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "<?xml version='1.0' encoding='UTF-8'?> <NewDataSet> <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://ww in /xml.php on line 62

When I echo it I het plain text in web page

Member Avatar
pritaeas
mod_pritaeas
11,295 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,832 [?]
Skill Endorsements: 155 [?]
Moderator
Featured
Sponsor
 
0
 

The weird characters before the xml tag probably cause this. Where do they come from?

Member Avatar
mehnihma
Posting Whiz in Training
239 posts since Oct 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
1
 

I had to use:
simplexml_load_string

That was the problem because of the string :)

Question Answered as of 1 Year Ago by pritaeas and cereal
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article