RSS Reader 编译但不显示
RSS Reader compiling but not displaying
我的数据可以很好地解析 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 文件似乎也很不错 large/not 让我复制+粘贴,但可以通过以下方式找到
www.abc.net.au/local/rss/recipes.xml
提前致谢!
您需要设置默认命名空间,如下所示:
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]});
}
}
我的数据可以很好地解析 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 文件似乎也很不错 large/not 让我复制+粘贴,但可以通过以下方式找到 www.abc.net.au/local/rss/recipes.xml
提前致谢!
您需要设置默认命名空间,如下所示:
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]});
}
}