Tutorial pratici per iPhone SDK v1.6 - Get a Free Blog
Tutorial pratici per iPhone SDK v1.6 - Get a Free Blog
Tutorial pratici per iPhone SDK v1.6 - Get a Free Blog
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
1<br />
2<br />
3<br />
4<br />
5<br />
6<br />
7<br />
8<br />
9<br />
10<br />
11<br />
12<br />
13<br />
14<br />
15<br />
16<br />
17<br />
18<br />
19<br />
20<br />
21<br />
22<br />
23<br />
24<br />
25<br />
26<br />
27<br />
28<br />
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName<br />
namespaceURI:(NSString *)namespaceURI<br />
qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{!<br />
! !<br />
! currentElement = [elementName copy];<br />
! if ([elementName isEqualToString:@"item"]) {<br />
! ! // inizializza tutti gli elementi<br />
! ! item = [[NSMutableDictionary alloc] init];<br />
! ! currentTitle = [[NSMutableString alloc] init];<br />
! ! currentDate = [[NSMutableString alloc] init];<br />
! ! currentSummary = [[NSMutableString alloc] init];<br />
! ! currentLink = [[NSMutableString alloc] init];<br />
! }<br />
}<br />
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName<br />
namespaceURI:(NSString *)namespaceURI<br />
qualifiedName:(NSString *)qName{<br />
!<br />
! if ([elementName isEqualToString:@"item"]) {<br />
! ! /* salva tutte le proprietà del feed letto nell'elemento<br />
"item", <strong>per</strong><br />
! ! poi inserirlo nell'array "elencoFeed" */<br />
! ! [item setObject:currentTitle forKey:@"title"];<br />
! ! [item setObject:currentLink forKey:@"link"];<br />
! ! [item setObject:currentSummary forKey:@"summary"];<br />
! ! [item setObject:currentDate forKey:@"date"];<br />
! !<br />
! ! [elencoFeed addObject:[item copy]];<br />
! }<br />
}<br />
Questi due metodi vengono richiamati, rispettivamente, quando inizia e quando finisce un<br />
elemento XML. Nel primo caso dovremo re-inizializzare tutti gli elementi, in modo da poter<br />
leggere un nuovo elemento senza errori. Al contrario, quando un elemento XML termina dovremo<br />
salvare tutti questi valori letti in un unico elemento (“item”) e inserirlo nella lista dei<br />
feed letti (“elencoFeed”).<br />
Per completare la definizione del parser ci mancano solo due metodi:<br />
<strong>Tutorial</strong> <strong>pratici</strong> <strong>per</strong> <strong>iPhone</strong> <strong>SDK</strong>! 127