Skip to main content
Participant
October 12, 2008
Question

Parsing multiple attributes from external XML file

  • October 12, 2008
  • 2 replies
  • 238 views
I'm not sure what I'm doing wrong but I'm using an external XML file to populate a video playlist. So I'm parsing the attributes like this:

tileList.addItem({label:item.attribute("description"),
label:item.attribute("details").toXMLString(),
data:item.attribute("src").toXMLString(),
source:thumbnail});;


But the "details" attribute is not showing up. Is there something I'm doing wrong?
The XML element that holds the attributes looks like this:

<vid description="My description"
details="More detailed description."
src="movies/myMovie.flv"
thumbnail="thumbnails/myImage.jpg" />

Help will be greatly appreciated.
This topic has been closed for replies.

2 replies

Participant
October 12, 2008
Thanks for the feedback abeall. Yes, I had tried that and the "details" data still does not show. This is the code of how I'm declaring the class and defining the XML properties

public class mediaPlaylist extends MovieClip {
private var xmlLoader:URLLoader;

public function mediaPlaylist():void {
xmlLoader = new URLLoader();
xmlLoader.addEventListener(Event.COMPLETE, playVideo);
xmlLoader.load(new URLRequest("videos.xml"));
}

public function playVideo(event:Event):void {
var myXML:XML = new XML(xmlLoader.data);
var item:XML;
for each(item in myXML.vid) {
var thumbnail:String;
if(item.hasOwnProperty("@thumbnail")>0) thumbnail = item.@thumbnail;
tileList.addItem({label:item.attribute("description"),
label:item.attribute("details").toXMLString(),
data:item.attribute("src").toXMLString(),
source:thumbnail});;
}
Perhaps there's something I'm missing. When I parse it like this:

tileList.addItem({label:item.attribute("*") .toXMLString(),

The "details" attributes" show up on the playlist and of course the "src" and "thumbnail". So now it presents the problem of trying to make the last two not show up. arghh!
October 12, 2008
Did you try:

tileList.addItem({label:item.@description,
label:item.@details,
data:item.@src,
source:thumbnail});

?