0

私は学校で xml の解析に取り組んでおり、Twitter の API を使用して作業しています。ツイートが投稿された日付を取得しようとしていますが、問題が発生しています。xml 内に異なる値を保持する同じ名前の 2 つの要素があります。ただし、一方は他方よりもネストされているため、論理的には、ネストされているものを確認したいと思います。どうすればそれを行うことができますか?

現在、すべてが完璧に機能しています。プロジェクトにさらに追加したいだけです。

これは、私が呼び出している didEndElement メソッドの例です。

 -(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:          (NSString *)namespaceURI qualifiedName:(NSString *)qName
{
//Creates an instance of the singleton to grab the array stored there
DataArraySingleton *singleton = [DataArraySingleton sharedArray];

//easy access to array
NSMutableArray *array = singleton.theArray;

//If the element ends with text
if ([elementName isEqualToString:@"text"])
{
    //Sets the value/key pair for text
    [tweets setValue:currentXMLValue forKey:elementName];

}
//Same as above
if ([elementName isEqualToString:@"screen_name"])
{
    [tweets setValue:currentXMLValue forKey:elementName];
}
//Same as above
if ([elementName isEqualToString:@"profile_image_url"])
{
    [tweets setValue:currentXMLValue forKey:elementName];
}
//If the element ends with status
if ([elementName isEqualToString:@"status"])
{
    //Adds the objects collected above to the array
    [array addObject:tweets];

    //Resets the object TweetInformation to be called again above
    tweets = nil;

}
//Resets xml value
currentXMLValue = nil;
}

みんなありがとう

4

1 に答える 1

0

必要なネストされた日付要素の親タグを確認するコードを追加します。開始タグに遭遇したら、コードにフラグを設定します。ここで、日付タグに遭遇したら、フラグが設定されているかどうかを確認します。フラグが設定されていない場合は、日付タグを無視してください。親の終了タグを検出したら、フラグをリセットします。

于 2013-02-25T02:59:53.417 に答える