We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,608 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

curl get xml problem

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

3
Contributors
5
Replies
1 Day
Discussion Span
3 Months Ago
Last Updated
12
Views
Question
Answered
mehnihma
Posting Whiz in Training
234 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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

pritaeas
Posting Prodigy
Moderator
9,265 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,456
Skill Endorsements: 86

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!

cereal
Veteran Poster
1,144 posts since Aug 2007
Reputation Points: 344
Solved Threads: 221
Skill Endorsements: 22

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

mehnihma
Posting Whiz in Training
234 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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

pritaeas
Posting Prodigy
Moderator
9,265 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,456
Skill Endorsements: 86

I had to use:
simplexml_load_string

That was the problem because of the string :)

mehnihma
Posting Whiz in Training
234 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 3 Months Ago by pritaeas and cereal

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0715 seconds using 2.72MB