Jump to content

how to solve: XML Parsing Error: no element found


plusnplus

Recommended Posts

Hi..

 

I try to get google weather info into my website.

when i try this code:

<?php
header("content-type: text/xml");
$xmlData = file_get_contents("http://www.google.com/ig/api?weather=new york");
echo $xmlData;
?>

i got error : XML Parsing Error: no element found

 

but when i directly type http://www.google.com/ig/api?weather=new york into the browser, it give me the xml file.

Any idea how to solve this problem?

 

Thanks for any reply/ help

 

Link to comment
Share on other sites

Your browser automatically adds urlencoding for you, when you do it in PHP you need to add it manually, or use urlencode()

 

the solution to your problem would be:

<?php
header("content-type: text/xml");
$xmlData = file_get_contents("http://www.google.com/ig/api?weather=new%20york");
echo $xmlData;
?>

 

There's always more than one way to do something, though. :P

Link to comment
Share on other sites

Hi pornophobic,

 

it is still give me the same error:

XML Parsing Error: no element found

 

it that possible the error because, my company block something in firewall?

 

but like i mention before i able to see without error if i type directly to browser(firefox):

http://www.google.com/ig/api?weather=new%20york

 

actually i try other weather api script from yahoo, still not show same error, but not if i put direct in browser.

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.