开发者

Flash doesnt like my Formtted XML

开发者 https://www.devze.com 2023-03-10 12:18 出处:网络
I am getting the following error: #1088: The markup in the document following 开发者_JAVA技巧the root element must be well-formed

I am getting the following error:

#1088: The markup in the document following 开发者_JAVA技巧the root element must be well-formed

I am calling a php script from AS3 that grabs some XML data from a website and echos it to a page.

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

to get around a cross domain issue.

The XML when viewing source in browser:

<?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>

I noticed it was using an XSL file to style the data in the browser. I think that is causing the issue:

My 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

?>

And finally my action script:

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();

Pretty straight forward. But I am not sure why I am not getting the XML to import into Flash. Even if I strip out all the XSL data with php is still does not like the formatting.

please help.


Maybe, this won't help you directly but I tested your code and everything works fine here: The XML content is traced in debug mode. I used the same AS3 code* and provided a PHP with exactly the same content on my web server.

Therefore, I would guess that the problem has nothing to do with the shown sourcecode and lies in code which is not shown here or maybe web server configurations.

--

*Changes:

  • changed the URL to my own web server
  • made the functions private (using FlashDevelop with Flex SDK -- maybe this is the sticking point)
  • myXML = new XML(e.target.data); -> var myXML:XML = new XML(e.target.data);
0

精彩评论

暂无评论...
验证码 换一张
取 消