0

I have a XML like:

<bodyText>
  <1 beginIndex="0" endIndex="723">
    The teddy bear is a soft toy in the form of a bear. Teddy bears are among the most popular gifts for children and are often given to adults to signify love, congratulations or sympathy.</1>

<2 beginIndex="724" endIndex="347">
    Morris Michtom saw the drawing of Roosevelt and was inspired to create a new toy. He created a little stuffed bear cub and put it in his shop window with a sign that read "Teddy's bear," after sending a bear to Roosevelt and receiving permission to use his name. 
</2>
</bodyText>

how do i search particular string in XML ? For ex: If a user enters "drawing of Roosevelt". The 2nd xml element contains this string and it should return 2(it should return paragraph no). How to find out ?

Marty
  • 39,033
  • 19
  • 93
  • 162
viji
  • 119
  • 2
  • 3
  • 12

1 Answers1

0

Convert xml to an internal class, lets call it MyEntry that has id ( the 1 and 2 values in your example, but put them as attribute, the name of the node is irrelevant, put "a" ), beginIndex, endIndex and value (your string) and put a method inside MyEntry in it like:

public function search( string:String ):Boolean
{
    return value.indexOf( string ) != -1;
}

//When you search for the string "drawing of Roosevelt":
for each( var entry:MyEntry in entries )
{
    if( entry.search( string ) )
    {
       trace( "Found!" );
       break;
    }
}
Discipol
  • 3,137
  • 4
  • 22
  • 41
  • Thanks. I am new to Flex and XML. I don't know about JSON. It would be good to hear new language jargon. – viji Aug 29 '13 at 05:16
  • json is very light weight, native flash encoding/decoding, its test like xml and its converted into flash object/number/string/boolean, etc. – Discipol Aug 29 '13 at 07:16