2011-06-03 64 views
0

我收到以下错误:闪存犯规像我Formtted XML

#1088: The markup in the document following the root element must be well-formed 

我打电话从AS3一个PHP脚本,从网站,它回声一个网页抓取一些XML数据。

myLoader.load(new URLRequest("http://www.mywebsite.com/my_test/my_Weather.php")); 

解决跨域问题。

在浏览器中查看源时,XML:

<?xml version="1.0" encoding="ISO-8859-1"?> 
<?xml-stylesheet href="latest_ob.xsl" type="text/xsl"?> 
<current_observation version="1.0" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:noNamespaceSchemaLocation="http://www.weather.gov/view/current_observation.xsd"> 
    <credit>NOAA's National Weather Service</credit> 
    <credit_URL>http://weather.gov/</credit_URL> 
    <image> 
     <url>http://weather.gov/images/xml_logo.gif</url> 
     <title>NOAA's National Weather Service</title> 

     <link>http://weather.gov</link> 
    </image> 
    <latitude>41.27</latitude> 
    <longitude>-80.67</longitude> 
    <observation_time>Last Updated on Jun 3 2011, 1:51 pm EDT</observation_time> 
     <observation_time_rfc822>Fri, 03 Jun 2011 13:51:00 -0400</observation_time_rfc822> 
    <weather>Mostly Cloudy</weather> 
    <temperature_string>71.0 F (21.7 C)</temperature_string> 
</current_observation> 

我注意到它是使用XSL文件的样式在浏览器中的数据。 我认为这是导致该问题:

我的PHP my_Weather.php:

<?PHP 

//ini_set("display_errors","2"); 
//ERROR_REPORTING(E_ALL); 

header('Content-type: text/xml'); 

$xml_data = file_get_contents("http://www.weather.gov/xml/current_obs/KYNG.xml"); 

echo $xml_data 

?> 

最后我的动作脚本:

var myXML:XML; 
var myLoader:URLLoader = new URLLoader(); 

myLoader.load(new URLRequest("http://www.mywebsite.com/my_test/my_Weather.php")); 
myLoader.addEventListener(Event.COMPLETE, processXML); 

function processXML(e:Event):void { 
    trace("load XML"); 
    myXML = new XML(e.target.data); 
    trace(myXML); 
    show_temp(myXML); 
} 

function show_temp(myXML):void 
{ 
    temp_info.text = myXML.temp_f[0]; 
} 

stop(); 

漂亮的直线前进。但我不确定为什么我没有将XML导入到Flash中。即使我用PHP去掉所有的XSL数据仍然不喜欢格式化。

请大家帮忙。

+1

要确认,当您浏览到http://www.mywebsite.com/my_test/my_Weather.php时,您是否看到XML? – jhocking 2011-06-03 19:20:03

+0

当您追踪e.target.data时会发生什么? – cwallenpoole 2011-06-03 19:21:46

+1

“http://www.weather.gov/xml/current_obs/KYNG.xml”不返回xml。 myXML = new XML(e.target.data);将无法解析它。 – 2011-06-03 19:52:49

回答

1

也许,这不会直接帮助你,但我测试了你的代码,并且在这里一切正常:XML内容在调试模式下被跟踪。我使用了相同的AS3代码*,并在我的Web服务器上提供了完全相同内容的PHP。

因此,我猜想这个问题与显示的源代码没有关系,并且存在于此处未显示的代码或可能是Web服务器配置中。

-

*更改:

  • 改变URL以自己的Web服务器
  • 为私有的功能(使用FlashDevelop使用Flex SDK - 也许这就是症结所在)
  • myXML = new XML(e.target.data); - > var myXML:XML = new XML(e.target.data);
+0

一旦我将SWF放到服务器上,我就在本地进行测试。以为我的所有权限设置正确,但显然不是。感谢您的帮助。 – Denoteone 2011-06-06 14:08:18