可能重复: e4x / AS3:如何访问一个节点,其名称中的破折号
我已经设置了命名空间,我的XML使用SMIL,我能拉一个元素的src属性是这样的:
my.node。@ SRC
它获取这是一些URL
不过,我还有一个ATTR称为系统比特率。由于负号的,我不能做 @系统码率
所以我尝试我通常做的是 my.node.attribute('系统比特率')
这是行不通的。
奇怪的是,连 my.node.attribute(SRC)
的作品。我怀疑这是由于命名空间?因此,如何让我出去的属性使用 ny.node.attribute
?
这是工作的唯一的事情就是 my.node.attributes()[1]
。 我知道这不是正道,所以我希望有人能赐教!
FYI我正与 SMIL 文件
**编辑**
下面是需要我使用的XML命名空间:
默认XML命名空间=新的命名空间(http://www.w3.org/2001/SMIL20/Language');
和我的工作与XML的一个例子:
< SMIL的xmlns =http://www.w3.org/2001/SMIL20/Language>
< HEAD>
< META NAME =标题内容=直播/>
< /头>
<身体GT;
<开关>
<视频SRC =myStreamName系统比特率=200000/>
< /开关>
< /身体GT;
< / SMIL>
**的DennisJaaman code样品**
默认XML命名空间=新的命名空间(http://www.w3.org/2001/SMIL20/Language');
VAR的xml:XML = XML(event.target.data);
每个(VAR○:XML在xml.body ['开关']视频){
(!HS)如果HS = O;
其他 {
迹(o.attributes()[1]); // 作品
跟踪(O @网址。); //不能正常工作或(使我不知道关于NS的问题
跟踪(O ['@系统比特率']); //不起作用
跟踪(o.attribute(@系统比特率)//不起作用
//等等等等,我只留了几个在这里
}
}
解决方案
尝试下面的示例中使用方括号,如:
默认XML命名空间=新的命名空间(http://www.w3.org/2001/SMIL20/Language);
VAR xmlSmpl:XML =< SMIL的xmlns =http://www.w3.org/2001/SMIL20/Language>
< HEAD>
< META NAME =标题内容=直播/>
< /头>
<身体GT;
<开关>
<视频SRC =myStreamName系统比特率=200000/>
< /开关>
< /身体GT;
&所述; / SMIL取代;
跟踪(xmlSmpl.body ['开关'] ['视频'] ['@系统比特率']);
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
}
}
解决方案
Try to use square brackets like in the sample below:
default xml namespace = new Namespace("http://www.w3.org/2001/SMIL20/Language");
var xmlSmpl: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>;
trace (xmlSmpl.body['switch']['video']['@system-bitrate']);