AS3读取XML问题
xml文件内容如下:<PlayList><itemGuid="6a"VVCount="0"PLCount="0"DingCount="0"Name="2012-08-30...
xml文件内容如下:
<PlayList>
<item Guid="6a" VVCount="0" PLCount="0" DingCount="0" Name="2012-08-30" Duration="437" CreateDate="2012-08-30 17:51:00" Keyword="qq" CategoryName="q" BigPosterUrl="http://127.0.0.1/001.jpg" SmallPosterUrl="http://127.0.0.1/002.jpg" VideoPlayUrl="http://127.0.0.1/001.mp4" PlayerUrl="http://127.0.0.1/001.shtml" CPID="a5" CategroyId="0019-0055-0000" progID="176419" progName="20120830" progUrl="http://127.0.0.1/001.shtml" progXML="" teleplayindex="1" ColumnName="ww" ColumnFile="" Actor="" VipColumnID="" VipColumnUrl="" SE_Title="qqq" WapStatus="0"></item>
</PlayList>
AS3代码如下:
public function test(s:String):Object{
var data:Object;
var xml:XML;
data = {"status":404};
try {
XML.ignoreComments = true;
XML.ignoreWhitespace = true;
XML.ignoreProcessingInstructions = true;
xml = new XML(s);
} catch(e:Error) {
return (data);
};
if (typeof(xml["item"]) == "undefined"){
return (data);
};
return ({
"status":200,
"data":{
"flv":xml["item"].@VideoPlayUrl,
"time":0
}
});
}
用AS3读取XML中的VideoPlayUrl值(即是http://127.0.0.1/001.mp4)应该怎么写?
xml["item"].@VideoPlayUrl我这样写读取不到 展开
<PlayList>
<item Guid="6a" VVCount="0" PLCount="0" DingCount="0" Name="2012-08-30" Duration="437" CreateDate="2012-08-30 17:51:00" Keyword="qq" CategoryName="q" BigPosterUrl="http://127.0.0.1/001.jpg" SmallPosterUrl="http://127.0.0.1/002.jpg" VideoPlayUrl="http://127.0.0.1/001.mp4" PlayerUrl="http://127.0.0.1/001.shtml" CPID="a5" CategroyId="0019-0055-0000" progID="176419" progName="20120830" progUrl="http://127.0.0.1/001.shtml" progXML="" teleplayindex="1" ColumnName="ww" ColumnFile="" Actor="" VipColumnID="" VipColumnUrl="" SE_Title="qqq" WapStatus="0"></item>
</PlayList>
AS3代码如下:
public function test(s:String):Object{
var data:Object;
var xml:XML;
data = {"status":404};
try {
XML.ignoreComments = true;
XML.ignoreWhitespace = true;
XML.ignoreProcessingInstructions = true;
xml = new XML(s);
} catch(e:Error) {
return (data);
};
if (typeof(xml["item"]) == "undefined"){
return (data);
};
return ({
"status":200,
"data":{
"flv":xml["item"].@VideoPlayUrl,
"time":0
}
});
}
用AS3读取XML中的VideoPlayUrl值(即是http://127.0.0.1/001.mp4)应该怎么写?
xml["item"].@VideoPlayUrl我这样写读取不到 展开
1个回答
展开全部
错误的代码:
XML.ignoreComments = true;
XML.ignoreWhitespace = true;
XML.ignoreProcessingInstructions = true;
因为ignoreComments,ignoreWhitespace,ignoreProcessingInstructions,并不是XMl的静态方法,所以这样写是错误的,但是,as并不会显示出错误,因为你使用了try,所以你得到的一直都是
data = {"status":404};
解决方法,将XML改成xml,之后将xml = new XML(s);放到前面去,如下
try {
xml = new XML(s);
xml.ignoreComments = true;
xml.ignoreWhitespace = true;
xml.ignoreProcessingInstructions = true;
} catch (e:Error) {
return (data);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询