|
-
[RESOLVED] Troubles parsing XML in AS3
Greetings,
Perhaps someone can help with this... Having trouble breaking down the XML. The following function is called on a succesful file load:
function XMLLoaded(e:Event):void
{
trace("Loaded XML.");
var theXML = new XML(e.target.data);
var theTracks:XMLList = theXML.playlist.trackList.track;
trace(theXML.playlist);
trace(theTracks[0]);
...
The debugger shows me that theXML variable has indeed been loaded with the file contents. But the first trace yields no output and the second one is undefined.
Here's the XML file:
<playlist>
<trackList>
<track>
<title>Test 1.1</title>
<location>file:///music/br_openingtitles.mp3</location>
</track>
<track>
<title>Test 1.2</title>
<location>file:///music/clarinetquintet.mp3</location>
</track>
<track>
<title>Test 1.3</title>
<location>file:///music/correlation.mp3</location>
</track>
<track>
<title>Test 1.4</title>
<location>file:///music/hostage.mp3</location>
</track>
</trackList>
</playlist>
Any help greatly appreciated!
-
OK, I'll reply to my own post.
var theTracks:XMLList = theXML.playlist.trackList.track
This doesn't work because the XMLList shouldn't reference the root element (playlist); the following code *does* work:
var theTracks:XMLList = theXML.trackList.track
Also note: relative pathnames don't appear to work.
Sorry if this is all very basic...perhaps this post will help someone in the future.
Cheers,
Nick
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|