A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Most efficient way to search all children for a keyword with E4X?

  1. #1

    Most efficient way to search all children for a keyword with E4X?

    I've been experimenting with searching and filtering XML and displaying results and can't seem to google my way to the right answer so...

    Is there any way to simplify the expression below so it searches all children of each item without using the 'or' statement? If each item has 50 children, I'm guessing that using 50 'or' statements is not the way to go.

    What I'd like to do is search each item and return it if it contains "color" in any of the children, be it name, description...

    Any advice would be much appreciated.

    Code:
    var myXML:XML = 
    	<items>
    		<item name="item1">
    			<name>color magic marker</name>
    			<description>no keyword here.</description>
    		</item>
    		<item name="item2">
    			<name>pen</name>
    			<description>blah blah</description>
    		</item>
    		<item name="item3">
    			<name>magic marker</name>
    			<description>color here</description>
    		</item>
    	</items>;
    
    trace(myXML.item.( /color/.test(name) || /color/.test(description) ));

  2. #2
    Figured it out

    trace(myXML.item.( /color/.test(*) ));

    but that includes node names so

    trace(myXML.item.( />.*?color.*?</.test(*) ));


    I guess the next challenge is to weight the search results so that the results with the most matches start on top!
    Last edited by sirzooass; 03-09-2011 at 06:41 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center