可能的重复:
e4x / as3:如何访问名称中带有破折号的节点。 https://stackoverflow.com/questions/5317404/e4x-as3-how-to-access-a-node-with-a-dash-in-its-name
我已将 XML 的命名空间设置为使用 SMIL,并且可以通过以下方式提取元素的 src 属性:
my.node.@src
得到“这是某个 URL”
但是,我有另一个称为“系统比特率”的属性。由于减号,我不能这样做@system-bitrate
所以我尝试了我通常做的事情my.node.attribute('system-bitrate')
这是行不通的。
奇怪的是,甚至没有my.node.attribute('src')
作品。我怀疑这是由于命名空间造成的?那么如何使用来获取属性ny.node.attribute
?
唯一有效的是my.node.attributes()[1]
. 我知道这不是“正确的方法”,所以我希望有人能启发我!
仅供参考,我正在合作SMIL http://www.w3schools.com/smil/smil_files.asp files
** 编辑 **
以下是我正在使用的 XML 所需的命名空间:default xml namespace = new Namespace('http://www.w3.org/2001/SMIL20/Language');
我正在使用的 XML 示例:
<smil xmlns="http://www.w3.org/2001/SMIL20/Language">
<head>
<meta name="title" content="Live"/>
</head>
<body>
<switch>
<video src="myStreamName" system-bitrate="200000"/>
</switch>
</body>
</smil>
** DennisJaaman 的代码示例 **
default xml namespace = new Namespace('http://www.w3.org/2001/SMIL20/Language');
var xml:XML = XML(event.target.data);
for each(var o:XML in xml.body['switch'].video) {
if(!hs) hs = o;
else {
trace(o.attributes()[1]); // works
trace(o.@url); // doesn't work either (makes me wonder about NS issues
trace(o['@system-bitrate']); // doesn't work
trace(o.attribute('@system-bitrate') // doesn't work
// etc etc, I just left a few in here
}
}