Ik gebruik de volgende code in de .m file (stuk code met parser):
Header file:
en onder viewdidload:
Maar de XML weergeeft ie niet maar haalt ie wel keurig op zie ik aan de NSlogs
in de .xib file heb ik niks toevoegt aan 'view' omdat ik simpelweg niet weet welk object ik moet gebruiken voor de weergave en of dit wel nodig is.

Weet iemand wat ik over het hoofd zie of vergeet?
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
| - (void)parserDidStartDocument:(NSXMLParser *)parser{ NSLog(@"File found and parsing started"); } - (void)parseXMLFileAtURL: (NSString *)URL;{ NSString *agentString = @"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-us) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/3.2.1 Safari/525.27.1"; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: [NSURL URLWithString:URL]]; [request setValue:agentString forHTTPHeaderField:@"User-Agent"]; xmlFile = [ NSURLConnection sendSynchronousRequest:request returningResponse: nil error: nil ]; articles = [[NSMutableArray alloc] init]; errorParsing= NO; rssParser = [[NSXMLParser alloc] initWithData:xmlFile]; [rssParser setDelegate:self]; // You may need to turn some of these on depending on the type of XML file you are parsing [rssParser setShouldProcessNamespaces:NO]; [rssParser setShouldReportNamespacePrefixes:NO]; [rssParser setShouldResolveExternalEntities:NO]; [rssParser parse]; } - (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError { NSString *errorString = [NSString stringWithFormat:@"Error code %i", [parseError code]]; NSLog(@"Error parsing XML: %@", errorString); errorParsing=YES; } - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{ currentElement = [elementName copy]; ElementValue = [[NSMutableString alloc] init]; if ([elementName isEqualToString:@"intro"]) { item = [[NSMutableDictionary alloc] init]; } } - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{ [ElementValue appendString:string]; } - (void)parserDidEndDocument:(NSXMLParser *)parser { if (errorParsing == NO) { NSLog(@"XML processing done!"); } else { NSLog(@"Error occurred during XML processing"); } } |
Header file:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| #import <UIKit/UIKit.h> @class ontfsViewController; @interface artikels : UIViewController { ontfsViewController *detailViewController; IBOutlet UIWebView *errorView; //xml NSXMLParser *rssParser; NSMutableArray *articles; NSMutableDictionary *item; NSString *currentElement; NSMutableString *ElementValue; BOOL errorParsing; } @property (nonatomic, retain) IBOutlet ontfsViewController *detailViewController; @end |
en onder viewdidload:
code:
1
2
3
4
5
6
7
8
| - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. [self parseXMLFileAtURL:@"http://****.com/get_recent_posts.xml"]; } |
Maar de XML weergeeft ie niet maar haalt ie wel keurig op zie ik aan de NSlogs
code:
1
2
3
4
5
6
| 2011-12-11 17:35:22.820 [18712:f803] File found and parsing started 2011-12-11 17:35:22.821 [18712:f803] title 2011-12-11 17:35:22.821 [18712:f803] title 2011-12-11 17:35:22.822 [18712:f803] title 2011-12-11 17:35:22.822 [18712:f803] title 2011-12-11 17:35:22.823 [18712:f803] XML processing done! |
in de .xib file heb ik niks toevoegt aan 'view' omdat ik simpelweg niet weet welk object ik moet gebruiken voor de weergave en of dit wel nodig is.

Weet iemand wat ik over het hoofd zie of vergeet?
Front-end developer.