Skip to main content
Inspiring
October 6, 2008
Answered

need E4X help

  • October 6, 2008
  • 3 replies
  • 390 views
I can't get my E4X search to work and wonder if someone will help me. I know that my xml is loading.

when I type
trace(pXML.usr[0].@nme)
it returns Bill.
but when I type
trace(pXML.usr.@nme=="Bill")
it returns false.

Can someone tell me whats wrong with my search sytax? I'm trying to return all items that which have a nme attribute value of "Bill"

The relevant portion of my code and the xml are attached.

Thanks,
Casey
This topic has been closed for replies.
Correct answer Newsgroup_User
caseymanx,

> when I type
> trace(pXML.usr[0].@nme)
> it returns Bill.
> but when I type
> trace(pXML.usr.@nme=="Bill")
> it returns false.

Separate that expression with its own pair of parentheses:

pXML.user[0].(@nme == "Bill")


David Stiller
Adobe Community Expert
Dev blog, http://www.quip.net/blog/
"Luck is the residue of good design."


3 replies

Inspiring
October 6, 2008
> I think David may be wrong here. What he's shown is how
> you would pull out any records where the attribute equals
> Bill.

That was my interpretation of what Casey was asking for.

>> Can someone tell me whats wrong with my search sytax?
>> I'm trying to return all items that which have a nme attribute
>> value of "Bill"

The return value of the code I suggested is an instance of the XMLList
class. For example, this variant should put "true" in your Output panel:

trace(pXML.usr.(@nme=="Bill") is XMLList);

... and this variant will should put "1", because your sample code only
contained a single element whose nam attribute was Bill:

trace(pXML.usr.(@nme=="Bill").length());

If it helps, you can store the return value in a new variable and
retrieve your data from it using further E4X syntax:

var filteredResult:XMLList = pXML.usr.(@nme=="Bill");
trace(filteredResult.toXMLString());
trace(filteredResult[0].@nme);
// etc.


David Stiller
Adobe Community Expert
Dev blog, http://www.quip.net/blog/
"Luck is the residue of good design."


Colin Holgate
Inspiring
October 6, 2008
I think David may be wrong here. What he's shown is how you would pull out any records where the nme attribute equals Bill. Your test failed because you had [0] in one trace, but not in the other. This traces true:

trace(pXML.usr[0].@nme=="Bill")
Newsgroup_UserCorrect answer
Inspiring
October 6, 2008
caseymanx,

> when I type
> trace(pXML.usr[0].@nme)
> it returns Bill.
> but when I type
> trace(pXML.usr.@nme=="Bill")
> it returns false.

Separate that expression with its own pair of parentheses:

pXML.user[0].(@nme == "Bill")


David Stiller
Adobe Community Expert
Dev blog, http://www.quip.net/blog/
"Luck is the residue of good design."