simplexml加载谷歌天气API问题

发布于 2024-10-31 04:00:11 字数 2362 浏览 1 评论 0原文

您好,我的 google 天气 api 一直遇到问题,出现错误警告:simplexml_load_string() [function.simplexml-load-string]:实体:第 2 行:解析器错误 ....

我尝试使用主要作者的脚本(认为这是我编辑的脚本)但我仍然遇到这个错误我尝试了2 //komunitasweb.com/2009/09/showing-the-weather-with-php-and-google-weather-api/

//tips4php.net/2010/07/local-weather-with-php-and-google -weather/

奇怪的是,有时它会自行修复,然后又回到错误,我已经使用它几个月了,没有任何问题,这只是昨天发生的。作者的演示页面也正在运行,但我有完全相同的代码,请提供帮助。

这是我的网站 http://j2sdesign.com/weather/widgetlive1.php

@Mike 我添加了你的代码

<?
$xml = file_get_contents('http://www.google.com/ig/api?weather=jakarta');  if (!     simplexml_load_string($xml)) {   file_put_contents('malformed.xml', $xml); }
$xml = simplexml_load_file('http://www.google.com/ig/api?weather=jakarta');
$information = $xml->xpath("/xml_api_reply/weather/forecast_information");
$current = $xml->xpath("/xml_api_reply/weather/current_conditions");
$forecast_list = $xml->xpath("/xml_api_reply/weather/forecast_conditions");

?>

并列出了错误列表,但我似乎看不到错误,因为它一直在自行修复,然后一段时间后再次回到错误,

这是文件的内容

<?php  include_once('simple_html_dom.php');  // create doctype $dom = new DOMDocument("1.0");  
// display document in browser as plain text 
// for readability purposes //header("Content-Type: text/plain");  
// create root element 
$xmlProducts = $dom->createElement("products"); 
$dom->appendChild($xmlProducts);  
$pages = array(     'http://myshop.com/small_houses.html',     'http://myshop.com/medium_houses.html',     'http://myshop.com/large_houses.html' )   foreach($pages as $page) {     $product = array();     $source = file_get_html($page);      foreach($source->find('img') as $src)     {         if (strpos($src->src,"http://myshop.com") === false)         {             $product['image'] = "http://myshop.com/$src->src";         }     }      foreach($source->find('p[class*=imAlign_left]') as $description)     {         $product['description'] =  $description->innertext;     }      foreach($source->find('span[class*=fc3]') as $title)     {         $product['title'] =  $title->innertext;     }      //debug perposes!      echo "Current Page: " . $page . "\n";     print_r($product);     echo "\n\n\n"; //Clear seperator } ?>

Hi I have been having problems with the google weather api having errors Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 2: parser error ....

I tried to use the script of the main author(thinking it was my edited script) but still I am having this errors I tried 2
//komunitasweb.com/2009/09/showing-the-weather-with-php-and-google-weather-api/

and

//tips4php.net/2010/07/local-weather-with-php-and-google-weather/

The weird part is sometimes it fixes itself then goes back again to the error I have been using it for months now without any problem, this just happened yesterday. Also the demo page of the authors are working but I have the same exact code any help please.

this is my site http://j2sdesign.com/weather/widgetlive1.php

@Mike I added your code

<?
$xml = file_get_contents('http://www.google.com/ig/api?weather=jakarta');  if (!     simplexml_load_string($xml)) {   file_put_contents('malformed.xml', $xml); }
$xml = simplexml_load_file('http://www.google.com/ig/api?weather=jakarta');
$information = $xml->xpath("/xml_api_reply/weather/forecast_information");
$current = $xml->xpath("/xml_api_reply/weather/current_conditions");
$forecast_list = $xml->xpath("/xml_api_reply/weather/forecast_conditions");

?>

and made a list of the error but I can't seem to see the error cause it's been fixing itself then after sometime goes back again to the error

here is the content of the file

<?php  include_once('simple_html_dom.php');  // create doctype $dom = new DOMDocument("1.0");  
// display document in browser as plain text 
// for readability purposes //header("Content-Type: text/plain");  
// create root element 
$xmlProducts = $dom->createElement("products"); 
$dom->appendChild($xmlProducts);  
$pages = array(     'http://myshop.com/small_houses.html',     'http://myshop.com/medium_houses.html',     'http://myshop.com/large_houses.html' )   foreach($pages as $page) {     $product = array();     $source = file_get_html($page);      foreach($source->find('img') as $src)     {         if (strpos($src->src,"http://myshop.com") === false)         {             $product['image'] = "http://myshop.com/$src->src";         }     }      foreach($source->find('p[class*=imAlign_left]') as $description)     {         $product['description'] =  $description->innertext;     }      foreach($source->find('span[class*=fc3]') as $title)     {         $product['title'] =  $title->innertext;     }      //debug perposes!      echo "Current Page: " . $page . "\n";     print_r($product);     echo "\n\n\n"; //Clear seperator } ?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伴我老 2024-11-07 04:00:11

simplexml_load_string() 失败时,您需要将尝试加载的数据存储在某处以供查看。检查数据是诊断导致错误的原因的第一步。

$xml = file_get_contents('http://example.com/file.xml');

if (!simplexml_load_string($xml)) {
  file_put_contents('malformed.xml', $xml);
}

When simplexml_load_string() fails you need to store the data you're trying to load somewhere for review. Examining the data is the first step to diagnose what it causing the error.

$xml = file_get_contents('http://example.com/file.xml');

if (!simplexml_load_string($xml)) {
  file_put_contents('malformed.xml', $xml);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文