iCulture forum | iPhone, iPad,  iPod touch, Apple TV en iOS

iCulture forum | iPhone, iPad, iPod touch, Apple TV en iOS (https://forum.iculture.nl/)
-   Ontwikkelen voor iOS (https://forum.iculture.nl/f133/development/f58/ontwikkelen-voor-ios/)
-   -   XMl weergeeft niet in xcode/objective C (https://forum.iculture.nl/f133/development/f58/ontwikkelen-voor-ios/106784-xml-weergeeft-niet-xcode-objective-c.html)

nathanchunkie 11-12-11 18:29

XMl weergeeft niet in xcode/objective C
 
Ik gebruik de volgende code in de .m file (stuk code met parser):

Code:

- (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:

#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

Onder viewdidload:

Code:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self parseXMLFileAtURL:[NSURL URLWithString:@"http://***.com/app/get_recent_posts.xml"]];


}

Maar de XML weergeeft ie niet maar haalt ie wel keurig op zie ik aan de NSlogs

Code:

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.


http://cl.ly/3s193j1r0Q3d1d3s2V3i/Sc...2017.39.56.png

Weet iemand wat ik over het hoofd zie of vergeet? In tabel weergeven.


Update:

Citaat:

2011-12-11 18:35:49.260 [19268:f803] artikelen ophalen
2011-12-11 18:35:49.284 [19268:f803] -[NSURL length]: unrecognized selector sent to instance 0x6a53170
2011-12-11 18:35:49.285 [19268:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURL length]: unrecognized selector sent to instance 0x6a53170'
*** First throw call stack:
(0x13c2052 0x1553d0a 0x13c3ced 0x1328f00 0x1328ce2 0x12cad48 0x12d5d5d 0x93d49f 0x93d3df 0x93d38a 0x3e4f 0x48a8 0xdf64e 0xdf941 0xf147d 0xf166f 0xf193b 0xf23df 0xf2986 0xf25a4 0x3783 0xa971d 0xa9952 0x93186d 0x1396966 0x1396407 0x12f97c0 0x12f8db4 0x12f8ccb 0x12ab879 0x12ab93e 0x19a9b 0x26c8 0x2625 0x1)
terminate called throwing an exceptionsharedlibrary apply-load-rules all
(gdb)
Bij ophalen artikelen nu.

DJ14 11-12-11 18:45

Allereerst: je declareert je eigen functies niet in je header file.
Ten tweede: je header conformeert niet aan het NSXMLParser protocol.
Ten derde: waarom "artikels : UIViewController {" ? Gebruikelijk is "ontfsViewController : UIViewController {" in de header.
Ten vierde: je gebruikt geen logische user agent, is een klein detail.
Ten vijfde: zie aanpassing van je functie hieronder

EDIT:

Code:

- (void)parseXMLFileAtURL: (NSURL *)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:
 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];

 }


Heb nog niet verder gekeken, maar probeer dit eerst eens:

Code:

#import <UIKit/UIKit.h>

@interface ontfsViewController : UIViewController <NSXMLParserDelegate> {

    ontfsViewController *detailViewController;

    IBOutlet UIWebView *errorView;

    //xml
    NSXMLParser *rssParser;
    NSMutableArray *articles;
    NSMutableDictionary *item;
    NSString *currentElement;
    NSMutableString *ElementValue;
    BOOL errorParsing;
}

@property (nonatomic, retain) IBOutlet ontfsViewController *detailViewController;

- (void)parseXMLFileAtURL: (NSURL *)URL;

@end


nathanchunkie 11-12-11 18:57

Citaat:

xmlFile = [ NSURLConnection sendSynchronousRequest:request returningResponse: nil error: nil ];
Geeft fout: Use of undeclared indentifier 'XmlFile'

Moet het volgende zijn toch?

Citaat:

NSData *xmlFile = [ NSURLConnection sendSynchronousRequest:request returningResponse: nil error: nil ];

en:

uit je edit:

Citaat:

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:
URL];
geeft waring:

http://cl.ly/3h2J3X3u3F0e0R1H1h35/Sc...2018.57.28.png

DJ14 11-12-11 19:50

Probleem "verholpen" via iChat.


Alle tijden zijn GMT +2. Het is nu 08:42.