Flex checking if an XMLList contains a child node value using E4x

This is a simple question that took me a while to figure out. I know I can just loop through the contents of an XMLList and check manually if a certain child node’s value exists or not; however, I wanted a simple one-liner.

Here’s an example:

Description:

I want to find out if the string “JACKPOT” is contained within the child node value of this XMLList:

XMLList:

var list:XMLList =

<>

<Item>

<SubItem>123</SubItem>

</Item>

<Item>

<SubItem>JACKPOT</SubItem>

</Item>

<Item>

<SubItem>123</SubItem>

</Item>

</>;

E4x code (returns true or false if exists):

list.child("Item").(text().toString() == "JACKPOT").length() != 0
Advertisements

One thought on “Flex checking if an XMLList contains a child node value using E4x

  1. Thanks a lot for sharing this with all of us you really know what you’re talking approximately!

    Bookmarked. Kindly additionally visit my website =).
    We may have a hyperlink trade contract among us

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s