Member Avatar for mehnihma

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

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

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!

commented: Thanks, overlooked your post +2
Member Avatar for mehnihma

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

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

Member Avatar for mehnihma

I had to use:
simplexml_load_string

That was the problem because of the string :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.