XML Namespace issue…

By MSFX | Jun 11, 2009

actionscript3

I’m creating a media player for a client and they are using an xspf feed (xml)

This looks something like below…

Code:

<?xml version="1.0" encoding="UTF-8"?>
<playlist version="1" xmlns="http://xspf.org/ns/0/">
    <trackList>
        <track><location>http://example.com/song_1.mp3</location></track>
        <track><location>http://example.com/song_2.mp3</location></track>
        <track><location>http://example.com/song_3.mp3</location></track>
    </trackList>
</playlist>


Initially I thought yeah, easy enough but the problem is that with the namespace declared in the 2nd line but not used at all within the document I cant get Flash to transverse the tree, I just get a blank trace as soon as I try anything other than the root XML.

i.e.

ActionScript Code:
var xml:XML; var xmlLoader:URLLoader; xmlLoader = new URLLoader(); xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded); xmlLoader.load(new URLRequest(“xspf.xml”)); function xmlLoaded(e:Event):void {     xml = XML(e.currentTarget.data);     trace(“This first trace works!!”);     trace(xml)     trace(\nThis second trace doesn’t work”)     trace(xml.trackList); }

Annoyingly the namespace isn’t actually used but it cant be removed as this is the format the player must play with :( Even more annoyingly the declared namespace isn’t even there - broken link. If I try the above code and delete the namespace it works as expected.

Ive tried using the xml.removeNamespace(…) command

ActionScript Code:
var xspf:Namespace = xml.namespace(); var xml2:XML = xml.removeNamespace(xspf);

but this only removes namespace instances, not the declaration :( and so it still doesnt work :(

Can anyone help fix this? Ive attached the fla (CS3) and an xml file in case anyone has a spare 5 minutes…

Cheers,

Matt / MSFX


Attached Files

zip demo.zip (7.7 KB)

actionscript3

Please reply at our Forum

Leave a Comment

If you would like to make a comment, please fill out the form below.

Name (required)

Email (required)

Website

Comments

© 2007 ActionScript 3.0