0

次のような XML があります。

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

XML で特定の文字列を検索するにはどうすればよいですか? 例: ユーザーが「ルーズベルトの絵」と入力した場合。2 番目の xml 要素にはこの文字列が含まれており、2 を返す必要があります (段落番号を返す必要があります)。調べる方法は?

4

1 に答える 1

0

xml を内部クラスに変換し、id (例では 1 と 2 の値ですが、それらを属性として入れます。ノードの名前は無関係です。「a」を入れます)、beginIndex、endIndex、value (あなたの文字列) を作成し、次のように MyEntry 内にメソッドを配置します。

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;
    }
}
于 2013-08-26T08:08:45.443 に答える