2

I am trying to send a query as part a the URL to obtain an XML file, and then trying to parse the XML file using NSXMLParser and initWithContentsOfURL. However the parser is not able to parse the file. I tested the parser with the same file, but this time the file was saved on the server (it was not being generated) and it worked just fine, so I know it is not a problem with the parser.

I have come to think that it does not parse it because I need to load the file before I try to parse it, or give the initWithContentsOfURL time to load the contents. So I tried to put those contents in a NSString and a NSData and using a sleep function as well as using a block but that did not work either.

What would be the best way to go about this problem?

Here is some of the code:

NSString *surl = [NSString stringWithFormat:@"http://lxsrv7.oru.edu/~maria_hernandez/query.xml"];
url = [NSURL URLWithString:surl];
NSString *curl = [[NSString alloc] initWithContentsOfURL:url];

NSLog(@"URL: %@", surl);
NSLog(@"URL Content: %@", curl);

SXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:receivedData];

//Other stuff we have tried:
NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:surl] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
NSURLResponse =  nil;
NSError = nil;
receivedData = [NSURLConnection sendSynchronousRequest: theRequest returningResponse: &theResponse error: &error];

Let me know if you have more questions or if you wish to see more code. Thanks!

BigBug
  • 6,202
  • 23
  • 87
  • 138
MariaH
  • 41
  • 3

1 Answers1

0

have you tried setting a delegate for the NSXMLParse that implements the NSXMLParserDelegate which has events for parsing the document

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSXMLParser_Class/Reference/Reference.html

ssmithstone
  • 1,219
  • 1
  • 10
  • 21
  • Yes, we use the NSXMLParserDelegate but I don't think it has a way for the initWithContentsOFURL to wait until the pages is loaded – MariaH Apr 23 '11 at 19:02