mam analizowania RSS z NSXMLParser i to działa dobrze dla tytułu i innych ciągów, ale jeden z elementów stanowi ów obraz jakKorzystanie NSXMLParser z CDATA
<!CDATA <a href="http:image..etc>
Jak mogę dodać, że jak mój obraz komórki w widoku mojej tabeli? Czy zdefiniowałbym to jako typ obrazu?
To co używam do mojej parsowania:
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
//NSLog(@"found this element: %@", elementName);
currentElement = [elementName copy];
if ([elementName isEqualToString:@"item"]) {
// clear out our story item caches...
item = [[NSMutableDictionary alloc] init];
currentTitle = [[NSMutableString alloc] init];
currentDate = [ [NSMutableString alloc] init];
currentSummary = [[NSMutableString alloc] init];
currentLink = [[NSMutableString alloc] init];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
//NSLog(@"ended element: %@", elementName);
if ([elementName isEqualToString:@"item"]) {
// save values to an item, then store that item into the array...
[item setObject:currentTitle forKey:@"title"];
[item setObject:currentLink forKey:@"link"];
[item setObject:currentSummary forKey:@"description"];
[item setObject:currentDate forKey:@"date"];
[stories addObject:[item copy]];
NSLog(@"adding story: %@", currentTitle);
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
//NSLog(@"found characters: %@", string);
// save the characters for the current item...
if ([currentElement isEqualToString:@"title"]) {
[currentTitle appendString:string];
} else if ([currentElement isEqualToString:@"link"]) {
[currentLink appendString:string];
} else if ([currentElement isEqualToString:@"description"]) {
[currentSummary appendString:string];
} else if ([currentElement isEqualToString:@"pubDate"]) {
[currentDate appendString:string];
}
}
Tak, jest tam adres URL obrazu. Jak mogę wyodrębnić adres URL obrazu za pomocą NSXMLParser? – Xcoder
Spójrz na napis wewnątrz sekcji CDATA. Jeśli jest to zawsze poprawny xml, odpal kolejną instancję NSXMLParser na * tym * łańcuchu znaków. Jeśli nie jest to poprawne XML, musisz wykonać polecenie Something Else ™, na przykład znaleźć tag ręcznie. – Justicle
CMSy takie jak Wordpress mają opis w tagach CDATA. Coder Iphone będzie prawdopodobnie poproszony o wyświetlenie tekstu opisu w czytniku RSS jako części swojej aplikacji, tak jak robią to wszystkie czytniki RSS. Odpowiedź GabrielN jest rozwiązaniem. –