Парсинг тега содержимого XML - PullRequest
0 голосов
/ 14 февраля 2012

Моя проблема в том, что я не могу разобрать тег из XML-файла.Он возвращает нулевое значение, я проверяю его, используя NSLog с% @.

Если бы кто-то мог указать мне решение, я был бы очень благодарен.

Вот код: BOOL processing =НЕТ;if (currentText) {

    // Remove newlines and whitespace from currentText
    NSString *processedText = [currentText stringByRemovingNewLinesAndWhitespace];

    // Process
    switch (feedType) {
        case FeedTypeRSS: {

            // Item
            if (!processed) {
                if ([currentPath isEqualToString:@"/rss/channel/item/title"]) { if (processedText.length > 0) item.title = processedText; processed = YES; }
                else if([currentPath isEqualToString:@"/rss/channel/item/url"]) { if (processedText.length > 0) item.image = processedText; processed = YES; }
                else if([currentPath isEqualToString:@"/rss/channel/item/category"]) { if (processedText.length > 0) item.category = processedText; processed = YES; }
                else if ([currentPath isEqualToString:@"/rss/channel/item/link"]) { if (processedText.length > 0) item.link = processedText; processed = YES; }
                else if ([currentPath isEqualToString:@"/rss/channel/item/guid"]) { if (processedText.length > 0) item.identifier = processedText; processed = YES; }
                else if ([currentPath isEqualToString:@"/rss/channel/item/description"]) { if (processedText.length > 0) item.summary = processedText; processed = YES; }
                else if ([currentPath isEqualToString:@"/rss/channel/item/content:encoded"]) { if (processedText.length > 0) item.content = processedText; processed = YES; }
                else if ([currentPath isEqualToString:@"/rss/channel/item/pubDate"]) { if (processedText.length > 0) item.date = [NSDate dateFromInternetDateTimeString:processedText formatHint:DateFormatHintRFC822]; processed = YES; }
                else if ([currentPath isEqualToString:@"/rss/channel/item/enclosure"]) { [self createEnclosureFromAttributes:currentElementAttributes andAddToItem:item]; processed = YES; }
                else if ([currentPath isEqualToString:@"/rss/channel/item/dc:date"]) { if (processedText.length > 0) item.date = [NSDate dateFromInternetDateTimeString:processedText formatHint:DateFormatHintRFC3339]; processed = YES; }
            }

            // Info
            if (!processed && feedParseType != ParseTypeItemsOnly) {
                if ([currentPath isEqualToString:@"/rss/channel/title"]) { if (processedText.length > 0) info.title = processedText; processed = YES; }
                else if([currentPath isEqualToString:@"/rss/channel/item/url"]) { if (processedText.length > 0) item.image = processedText; processed = YES; }
                else if([currentPath isEqualToString:@"/rss/channel/item/category"]) { if (processedText.length > 0) item.category = processedText; processed = YES; }
                else if ([currentPath isEqualToString:@"/rss/channel/description"]) { if (processedText.length > 0) info.summary = processedText; processed = YES; }
                else if ([currentPath isEqualToString:@"/rss/channel/link"]) { if (processedText.length > 0) info.link = processedText; processed = YES; }
            }

            break;
        }
        case FeedTypeRSS1: {

            // Item
            if (!processed) {
                if ([currentPath isEqualToString:@"/rdf:RDF/item/title"]) { if (processedText.length > 0) item.title = processedText; processed = YES; }
                else if([currentPath isEqualToString:@"/rss/channel/item/url"]) { if (processedText.length > 0) item.image = processedText; processed = YES; }
                else if([currentPath isEqualToString:@"/rss/channel/item/category"]) { if (processedText.length > 0) item.category = processedText; processed = YES; }
                else if ([currentPath isEqualToString:@"/rdf:RDF/item/link"]) { if (processedText.length > 0) item.link = processedText; processed = YES; }
                else if ([currentPath isEqualToString:@"/rdf:RDF/item/dc:identifier"]) { if (processedText.length > 0) item.identifier = processedText; processed = YES; }
                else if ([currentPath isEqualToString:@"/rdf:RDF/item/description"]) { if (processedText.length > 0) item.summary = processedText; processed = YES; }
                else if ([currentPath isEqualToString:@"/rdf:RDF/item/content:encoded"]) { if (processedText.length > 0) item.content = processedText; processed = YES; }
                else if ([currentPath isEqualToString:@"/rdf:RDF/item/dc:date"]) { if (processedText.length > 0) item.date = [NSDate dateFromInternetDateTimeString:processedText formatHint:DateFormatHintRFC3339]; processed = YES; }
                else if ([currentPath isEqualToString:@"/rdf:RDF/item/enc:enclosure"]) { [self createEnclosureFromAttributes:currentElementAttributes andAddToItem:item]; processed = YES; }
            }

метод вызова:

// Настройка внешнего вида ячеек табличного представления.- (UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}

// Configure the cell.
MWFeedItem *item = [itemsToDisplay objectAtIndex:indexPath.row];
if (item) {
    NSLog(@"content = %@",item.content);//<-------------------------------------------Returns a NULL
    // Process
    NSString *itemTitle = item.title ? [item.title stringByConvertingHTMLToPlainText] : @"[No Title]";
    NSString *itemSummary = item.summary ? [item.summary stringByConvertingHTMLToPlainText] : @"[No Summary]";

    // Set
    cell.textLabel.font = [UIFont boldSystemFontOfSize:15];
    cell.textLabel.text = itemTitle;
    NSMutableString *subtitle = [NSMutableString string];
    if (item.date) [subtitle appendFormat:@"%@: ", [formatter stringFromDate:item.date]];
    [subtitle appendString:itemSummary];
    cell.detailTextLabel.text = subtitle;

}
return cell;

}

С наилучшими пожеланиями

1 Ответ

1 голос
/ 14 февраля 2012

При синтаксическом анализе каждого элемента синтаксический анализатор возвращает символ пробела в качестве ответа из-за новой строки / табуляции / возврата каретки. Если вы реализовали методы обратного вызова (делегаты) синтаксического анализатора, тогда проверьте нулевые значения, и я не знаю, где вы реализовали (в том смысле, в котором метод делегата синтаксического анализатора имеет это) самый первый фрагмент.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...