Use AS3 to parse XML node attribute that has a colon

家住魔仙堡 提交于 2019-12-11 18:51:27

问题


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.


回答1:


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);



回答2:


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

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




回答3:


Use ::.

.@xml::lang

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



来源:https://stackoverflow.com/questions/9911534/use-as3-to-parse-xml-node-attribute-that-has-a-colon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!