0

I have the following XML document:

<tt xmlns="http://www.w3.org/ns/ttml" xmlns:tts="http://www.w3.org/ns/ttml#styling" xml:lang="en">
<head></head>
<body>
<div xml:lang="it">
<p begin="00:00:00" end="00:00:02" style="violet">first</p>
</div>
</body>
</tt>

I load the contents into my flash object using AS3 successfully. But how do print/trace the value of the attribute in <div xml:lang="it">? When I try the code:

trace(myxml.children()[1].children()[0].@xml:lang);

The compiler complains about the syntax error presented by the colon.

Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265
John
  • 32,403
  • 80
  • 251
  • 422

3 Answers3

3

In your xml there is no 'xml' namespace. Probably you missed it. Should be something like this:

<tt xmlns:xml="http://blabla.com" ... xml:lang="en">

Then you need to declare Namespace instance for accessing xml attributes, tags for that namespace:

var ns:Namespace = new Namespace("xml","http://blabla.com") ;

Then you can use this code to access attribute:

trace(myxml.children()[1].children()[0].@ns::lang);
Engineer
  • 47,849
  • 12
  • 88
  • 91
1

Perhaps use: .attribute('xml:lang') instead of .@xml:lang

http://help.adobe.com/en_US/FlashPlatform/beta/reference/actionscript/3/XML.html#attribute()

Hawks
  • 534
  • 3
  • 14
  • No more syntax error, but i'm also getting no output now. If I do a trace(myxml.children()[1].children()[0]), then the output is `

    first

    ` . Any ideas?
    – John Mar 28 '12 at 16:35
  • trace(myxml.children()[1].children()[0].attribute("xml:lang")) gives me nothing. I also try adding more attibutes to the div element, and none of them print from the .attribute() function. – John Mar 28 '12 at 16:38
1

Use ::.

.@xml::lang

http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7e6c.html

Ricardo Souza
  • 16,030
  • 6
  • 37
  • 69