使用AS3解析,有一个冒号的XML节点属性冒号、节点、有一个、属性

2023-09-09 21:55:07 作者:百分之百甜

我有以下的XML文档:

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>

我加载内容到成功使用AS3我的Flash对象。但是,如何打印/跟踪属性的值&LT; D​​IV XML:LANG =它&GT; ?当我尝试在code:

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

编译器抱怨由冒号psented语法错误$ P $。

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

推荐答案

在你的XML没有XML的命名空间。也许你错过了。应该是这样的:

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">

然后,你需要声明命名空间实例访问XML属性,标签的命名空间:

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

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

然后你可以使用这个code访问属性:

Then you can use this code to access attribute:

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