I am trying to dynamically create an XML file using php like this:
我试图使用PHP动态创建一个XML文件,如下所示:
header ("content-type: text/xml");
// create doctype
$dom = new DOMDocument("1.0");
// create root element
$root = $dom->createElement("tracklist");
$dom->appendChild($root);
$dom->formatOutput=true;
// create child element
foreach ($commonPlaylist as $value) {
$trackArray = getTrackForID($value['ID']);
$item = $dom->createElement("track");
$root->appendChild($item);
foreach ( $trackArray as $key => $value) {
$attr = $dom->createAttribute($key);
$item->appendChild($attr);
$attrValue = $dom->createTextNode($value);
$attr->appendChild($attrValue);
}
}
echo $dom->saveXML();
The output of the file is normal working xml
该文件的输出是正常工作的xml
<?xml version="1.0"?>
<tracklist>
<track ID="4" title="Track01" artist="Artist01" url="" length="" coverURL=""/>
<track ID="1" title="Track02" artist="Artist02" url="" length="" coverURL=""/>
<track ID="8" title="Track03" artist="Artist03" url="" length="" coverURL=""/>
</tracklist>
However if I want to get this data into as3 with the following code:
但是,如果我想使用以下代码将此数据转换为as3:
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest("getPlaylist.php"));
myLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(e:Event):void
{
var myXml:XML= new XML(e.target.data);
trace(myXml); // The variable is being traced.
}
I don't get any output at all. If I read the file as a String I get the whole PHP code. What am I doing wrong?
我根本没有得到任何输出。如果我将该文件作为String读取,我将获得整个PHP代码。我究竟做错了什么?
Thank you in advance for any help.
预先感谢您的任何帮助。
Regards, Matteo
3 个解决方案
#1
3
If I read the file as a String I get the whole PHP code
如果我将该文件作为String读取,我将获得整个PHP代码
It sounds like it's not being executed server-side. Are you hosting it on a server with PHP installed?
听起来它不是在服务器端执行。您是否在安装了PHP的服务器上托管它?
#2
2
Check the variable name
检查变量名称
- You're tracing myXML & the XML variable name is myXml
您正在跟踪myXML,XML变量名称是myXml
#3
0
Is processXML()
actually triggered? Try modifying it like in the following code and see if you get the "Hi!" part traced.
processXML()实际上是否被触发了?尝试修改它,如下面的代码,看看你是否得到“嗨!”部分追踪。
function processXML(e:Event):void
{
trace('Hi!');
var myXml:XML= new XML(e.target.data);
trace(myXML);
}
BTW, using a Flash debugger might be much more useful from trying to guess what went wrong :) Since the one shipped with Flash Professional sucks big time I can only recommend DeMonster debugger which saved me a lot of time while working on Flash projects. It also wouldn't hurt to have an HTTP traffic analysis tool like Fiddler.
顺便说一下,使用Flash调试器可能会更有用,因为我猜测出错了:)由于Flash Professional附带的那个很糟糕,我只能推荐DeMonster调试器,这使我在处理Flash项目时节省了大量时间。拥有像Fiddler这样的HTTP流量分析工具也没有什么坏处。
#1
3
If I read the file as a String I get the whole PHP code
如果我将该文件作为String读取,我将获得整个PHP代码
It sounds like it's not being executed server-side. Are you hosting it on a server with PHP installed?
听起来它不是在服务器端执行。您是否在安装了PHP的服务器上托管它?
#2
2
Check the variable name
检查变量名称
- You're tracing myXML & the XML variable name is myXml
您正在跟踪myXML,XML变量名称是myXml
#3
0
Is processXML()
actually triggered? Try modifying it like in the following code and see if you get the "Hi!" part traced.
processXML()实际上是否被触发了?尝试修改它,如下面的代码,看看你是否得到“嗨!”部分追踪。
function processXML(e:Event):void
{
trace('Hi!');
var myXml:XML= new XML(e.target.data);
trace(myXML);
}
BTW, using a Flash debugger might be much more useful from trying to guess what went wrong :) Since the one shipped with Flash Professional sucks big time I can only recommend DeMonster debugger which saved me a lot of time while working on Flash projects. It also wouldn't hurt to have an HTTP traffic analysis tool like Fiddler.
顺便说一下,使用Flash调试器可能会更有用,因为我猜测出错了:)由于Flash Professional附带的那个很糟糕,我只能推荐DeMonster调试器,这使我在处理Flash项目时节省了大量时间。拥有像Fiddler这样的HTTP流量分析工具也没有什么坏处。