I've done this lot of times, but now I'm missing something.... I'm searching for a node by looking for a value in an attribute.
我已经完成了很多次,但是现在我错过了一些东西......我正在通过查找属性中的值来搜索节点。
If I try to trace:
如果我试图追踪:
xmlQuestStructure.page[activePageIndex].label.@priority
The trace it's ok, and I can read High, Medium, Low (the values I'm expecting).
跟踪没关系,我可以读高,中,低(我期待的值)。
But if I try to trace this (where calculatedPriority is a String with value High, Medium or Low)
但是,如果我尝试跟踪这个(其中calculatedPriority是一个值为High,Medium或Low的字符串)
xmlQuestStructure.page[activePageIndex].label.(@priority == calculatedPriority)
I get ReferenceError: Error #1065: Variable priority is not defined
我得到ReferenceError:错误#1065:未定义变量优先级
What am I doing wrong? Thx for your help!
我究竟做错了什么?谢谢你的帮助!
1 个解决方案
#1
1
Most likely, your problem is that one of your label nodes DOESN'T have a priority attribute defined. When you use @ in e4x, it will throw an error if it comes to a XML node that doesn't have the attribute specified.
最有可能的问题是,您的某个标签节点没有定义优先级属性。在e4x中使用@时,如果涉及未指定属性的XML节点,则会引发错误。
If there is a possibility that your XMLnode could have the attribute omitted, then instead of using '@', use attribute()
.
如果您的XMLnode有可能省略该属性,那么使用attribute()而不是使用'@'。
So in your case, you could do this:
所以在你的情况下,你可以这样做:
xmlQuestStructure.page[activePageIndex].label.(attribute("priority") == calculatedPriority);
using attribute()
is more passive, and will ignore the node if it doesn't have the specified attribute, instead of throwing an error.
使用attribute()更加被动,如果节点没有指定的属性,则会忽略该节点,而不是抛出错误。
#1
1
Most likely, your problem is that one of your label nodes DOESN'T have a priority attribute defined. When you use @ in e4x, it will throw an error if it comes to a XML node that doesn't have the attribute specified.
最有可能的问题是,您的某个标签节点没有定义优先级属性。在e4x中使用@时,如果涉及未指定属性的XML节点,则会引发错误。
If there is a possibility that your XMLnode could have the attribute omitted, then instead of using '@', use attribute()
.
如果您的XMLnode有可能省略该属性,那么使用attribute()而不是使用'@'。
So in your case, you could do this:
所以在你的情况下,你可以这样做:
xmlQuestStructure.page[activePageIndex].label.(attribute("priority") == calculatedPriority);
using attribute()
is more passive, and will ignore the node if it doesn't have the specified attribute, instead of throwing an error.
使用attribute()更加被动,如果节点没有指定的属性,则会忽略该节点,而不是抛出错误。