Use AS3 to parse XML node attribute that has a col

2019-08-18 09:24发布

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.

3条回答
在下西门庆
3楼-- · 2019-08-18 10:01

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);
查看更多
趁早两清
4楼-- · 2019-08-18 10:14
登录 后发表回答