문제

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!

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top