我的数据正在解析xml并编译,但它没有显示任何内容。这两个框(' lb' - 列表框和' ta')是组件 - 我不确定这是否与其显示失败有关。不完全确定如何解决这个问题。
(概念:左侧的框应该使用列表组件显示列出的xml配方,单击时,应该在右侧框中显示源,这是一个动态文本区域。)
//create an event listener for the listbox, to change data when recipe is selected
lb.addEventListener(Event.CHANGE, itemChange);
//function to change data accordingly
function itemChange(e:Event):void
{
//textbox data to change to selected item in listbox
ta.text = lb.selectedItem.data;
}
//create a loader to listen for completion upon loading XML function
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onLoaded);
//declare xml variable
var xml:XML;
//function for event onLoaded
function onLoaded(e:Event):void
{
trace("successfully loaded");
/*consider the itemlist as an array, enabling pinpointing data
through the XML channel (such as description, title etc) to extract
the data I want to display.*/
xml = new XML(e.target.data);
var il:XMLList = xml.channel.items;
/*create a for loop to add data (in this instance the description text
from the channel of the XML file and also to take the title text from
the XML and display it in the listbox to convey content.*/
for(var i:uint=0; i<il.length(); i++)
{
lb.addItem({data:il.description.text()[i],
label:il.title.text()[i]});
}
trace(il);
}
//load the XML file from a URLRequest to the following website.
loader.load(new URLRequest("http://www.abc.net.au/local/rss/recipes.xml"));
xml文件似乎太大/不允许我复制+粘贴,但可以通过找到它 www.abc.net.au/local/rss/recipes.xml
提前致谢!
答案 0 :(得分:0)
您需要设置默认命名空间,如下所示:
function onLoaded(e:Event):void
{
trace("successfully loaded");
/*consider the itemlist as an array, enabling pinpointing data
through the XML channel (such as description, title etc) to extract
the data I want to display.*/
xml = new XML(e.target.data);
//Set the default namespace _before_ attempting to parse
var atom:Namespace = new Namespace("http://www.w3.org/2005/Atom");
default xml namespace = atom;
var il:XMLList = xml.channel.item; //you were attempting to access "items", but what you really want is "item"
/*create a for loop to add data (in this instance the description text
from the channel of the XML file and also to take the title text from
the XML and display it in the listbox to convey content.*/
for(var i:uint=0; i<il.length(); i++)
{
lb.addItem({data:il.description.text()[i],
label:il.title.text()[i]});
}
}