actionscript 3.0 and e4x: search strings inside an XML object
Find a defined string inside an XML object
// String to Find
var stringToFind:String = "Flash Media";
// XML Object
var myXML:XML =
<order>
<item id='101'>
<title>Technologies</title>
<desc>XML e4x rulez</desc>
</item>
<item id='102'>
<title>Adobe Products</title>
<desc>Flex, Flash, Air, FlashLite, Catalyst, Flash Media Server 2, ... </desc>
</item>
<item id='103'>
<title>Server Side Products</title>
<desc>Flash Media Server 3, Flash Collaborative Service, ColdFustion</desc>
</item>
</order>
// Loop over the XML items
for (var i:uint = 0; i < myXML.item.length(); i++) {
// Get the item description
var tempString:String = myXML.item[i].desc
/*
* Check if the defined word does exist in the description, displaying:
* - Node title
* - Node ID
* - XML node index (from 0 to N)
* - The searched word
*/
if (tempString.search(stringToFind) != -1) {
// This trace displays:
// ---> Adobe Products ( ID - 102 ) contains this word: 'Flash Media' (XML item index: 1 )
// ---> Server Side Products ( ID - 103 ) contains this word: 'Flash Media' (XML item index: 2 )
trace("--->", myXML.item[i].title, "( ID -", myXML.item[i].@id, ") contains this word: '" + stringToFind + "' (XML item index:", i, ")")
}
}




