我正在使用 Flash CS6 - Adobe AIR 3.3:我不想在我的 XML 中准确输入我想搜索的内容,而是想使用一个可以更改的动态变量来搜索不同的类别和日期。以下是我想使用的代码:
var someCategory:String = new String("food");
var someDay:String = new String("monday");
var locationsLoader:URLLoader = new URLLoader();
locationsLoader.load(new URLRequest("http://www.myfile.xml"));
locationsLoader.addEventListener(Event.COMPLETE, init);
//load xml
function init(e:Event):void
{
theXML = new XML(e.target.data);
theXML.ignoreWhitespace = true;
e.currentTarget.close();
for(var i:int = 0; i < theXML.someCategory.length(); i++)
{
if(theXML.someCategory[i].somdDay != "un")
{
//do soemthing
}
}
此代码目前仅在我在“for”和“if”循环中实际键入“food”和“monday”时才有效。有什么建议么?
XML将是...
<xml>
<food>
<monday>yes</monday>
</food>
<food>
<monday>yes 2</monday>
</food>
<food>
<monday>un</monday>
</food>
</xml>
这是目前有效的:
var someCategory:String = new String("food");
var someDay:String = new String("monday");
var locationsLoader:URLLoader = new URLLoader();
locationsLoader.load(new URLRequest("http://www.myfile.xml"));
locationsLoader.addEventListener(Event.COMPLETE, init);
//load xml
function init(e:Event):void
{
theXML = new XML(e.target.data);
theXML.ignoreWhitespace = true;
e.currentTarget.close();
for(var i:int = 0; i < theXML.food.length(); i++)
{
if(theXML.food[i].monday != "un")
{
//do soemthing
}
}