问题
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)
xmlQuestStructure.page[activePageIndex].label.(@priority == calculatedPriority)
I get ReferenceError: Error #1065: Variable priority is not defined
What am I doing wrong? Thx for your help!
回答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.
If there is a possibility that your XMLnode could have the attribute omitted, then instead of using '@', use 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.
来源:https://stackoverflow.com/questions/12587847/referenceerror-error-1065-variable-is-not-defined-when-searching-for-a-node-b