Home > Flash development, Flex development > E4X and namespaces

E4X and namespaces

December 9th, 2008 Randy Leave a comment Go to comments

Recently I struggled with trying to figure out why I could not traverse loaded XML data using E4X. In one case it was a RSS feed and in another it was Timed Text data. What these data sets have in common is that they declare name spaces. Consider this xml data:

XML:
  1. <tt aaa:lang="en" xmlns="http://www.w3.org/2006/04/ttaf1" xmlns:tts="http://www.w3.org/2006/04/ttaf1#styling" xmlns:aaa="http://www.w3.org/XML/1998/namespace">
  2.   <head>
  3.     <styling>
  4.       <style id="1" tts:textAlign="right"/>
  5.       <style id="2" tts:color="transparent"/>
  6.       <style id="3" style="2" tts:backgroundColor="white"/>
  7.       <style id="4" style="2 3" tts:fontSize="20"/>
  8.     </styling>
  9.   </head>
  10.   <body>
  11.     <div aaa:lang="en">
  12.       <p begin="00:00:00.25" dur="00:00:03.25">Dreamweaver users now have access to Flash video. Didn't have it before.</p>
  13.       <p begin="00:00:04.20" dur="00:00:03.07">And if you were to talk to a Dreamweaver user about three or four years ago</p>
  14.     </div>
  15.   </body>
  16. </tt>

I see that it declares a couple namespaces but I thought since the "p" nodes do not. This ...

Actionscript:
  1. trace(timedTextXML..p);

yields nothing. Yet this ...

Actionscript:
  1. if (timedTextXML.namespace("") != undefined){
  2.       default xml namespace = timedTextXML.namespace("");
  3. }
  4. trace(timedTextXML..p);

works fine.

Categories: Flash development, Flex development Tags:
  1. Darren Moxin
    June 16th, 2010 at 10:16 | #1

    Finally! A work around to this very frustrating problem. Thanks for posting this. Does the line:

    default xml namespace = timedTextXML.namespace("");

    ...basically remove the name space from the node?

    Thanks again,
    Darren

  1. No trackbacks yet.