• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

need E4X help

Explorer ,
Oct 06, 2008 Oct 06, 2008

Copy link to clipboard

Copied

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
TOPICS
ActionScript

Views

322

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Oct 06, 2008 Oct 06, 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."


Votes

Translate

Translate
LEGEND ,
Oct 06, 2008 Oct 06, 2008

Copy link to clipboard

Copied

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."


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 06, 2008 Oct 06, 2008

Copy link to clipboard

Copied

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")

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 06, 2008 Oct 06, 2008

Copy link to clipboard

Copied

LATEST
> 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."


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines