as3 命名空间 - 获取一个带有减号的属性
我已将 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 文件
** 编辑 **
这是我正在使用的 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>
** 代码示例丹尼斯贾曼 **
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
}
}
Possible Duplicate:
e4x / as3: How to access a node with a dash in its name.
I've set the namespace for my XML to use SMIL and I'm able to pull the src attribute of an element this way:
my.node.@src
which gets "this is some URL"
However, I have another attr called 'system-bitrate'. Because of the minus sign, I can't do @system-bitrate
So I attempted what I normally do which is my.node.attribute('system-bitrate')
which isn't working.
Oddly enough, not even my.node.attribute('src')
works. I suspect this is due to the namespace? So how to I get attributes out using ny.node.attribute
?
The only thing that works is my.node.attributes()[1]
. I know that's not the "right way" so I'm hoping someone can enlighten me!
FYI I'm working with SMIL files
** edit **
Here's the namespace required for the XML I'm using:default xml namespace = new Namespace('http://www.w3.org/2001/SMIL20/Language');
And an example of the XML I'm working with:
<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>
** code sample for 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
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试使用方括号,如下例所示:
Try to use square brackets like in the sample below:
看哪! QName 的力量!
关于属性(以及后代,子级...)的事情是它的参数是类型
*
(匿名)。这是因为它实际上不是一个字符串,它在后台被强制转换为 QName(没有 URI)。这意味着您正在默认 URI 下搜索上述 URI 下的内容。让我知道上面的代码是如何工作的。
Behold! The power of QName!
The thing about attribute (and descendant, and child...) is that its parameter is type
*
(anonymously). This is because it really isn't a String, it is coerced to a QName (without a URI) in the background. This means you were searching under the default URI for something under the URI above.Let me know how that code above works out.
查看这篇文章:
e4x / as3:如何访问名称中带有破折号的节点
******编辑****:
并使用以下表示法获取包含 - (破折号)的 XML 属性
这些不起作用:
有关更多信息,请检查LiveDocs
干杯
Check out this post:
e4x / as3: How to access a node with a dash in its name
******EDIT****:
And use the following notation to get XML Attributes that contain a - (dash)
These do not work:
For more info check the LiveDocs
Cheers