Note that there are some explanatory texts on larger screens.

plurals
  1. PONSXMLParser with encoded Data in String
    primarykey
    data
    text
    <p>I want to program a NSXMLParser and I have the data for this lying in a NSString (encoded). </p> <p>If I put the NSString to NSLog it gives me the right lines I need. But when I want to start the Parser with the data from that NSString it doesn't start.</p> <p>Here is my code:</p> <p>The interface:</p> <pre><code>@interface StundenplanParser () &lt;NSXMLParserDelegate&gt; @end </code></pre> <p>The method that gets called from the ViewController:</p> <pre><code> -(void)parserStart { // Create your request string with parameter name as defined in PHP file NSString *myRequestString = [NSString stringWithFormat:@"matr=%@&amp;pressme=%@",@"33886",@"S T A R T"]; // Create Data from request NSData *myRequestData = [NSData dataWithBytes: [myRequestString UTF8String] length: [myRequestString length]]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString: @"http://www2.htw-dresden.de/~rawa/cgi-bin/auf/raiplan_app.php"]]; // set Request Type [request setHTTPMethod: @"POST"]; // Set content-type [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"]; // Set Request Body [request setHTTPBody: myRequestData]; // Now send a request and get Response NSData *returnData = [NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil]; // Log Response NSString *response = [[NSString alloc] initWithBytes:[returnData bytes] length:[returnData length] encoding:NSASCIIStringEncoding]; NSLog(@"Response:%@\n",[response substringToIndex:64]); // If I would use NSASCIIStringEncoding in the following line, the data would be nil NSData *data = [response dataUsingEncoding:NSUTF8StringEncoding]; NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data]; if (!parser) NSLog(@"Error with parser"); else NSLog(@"parser successfully initialised"); [parser setDelegate:self]; [parser parse]; } </code></pre> <p>NOTE: In my response (NSString*) is the code that I want to parse. If I print it out using NSLog I see the source code of the website..</p> <p>Now I want to show only the elements the NSXMLParser found with this:</p> <pre><code>-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict { NSLog(@"found element: %@", elementName); } </code></pre> <p>I hope it's not a problem that I left the url in the code. I just want to parse the schedule from my university.</p> <p>I hope you understand what I mean and you could help me.</p> <p>EDIT: My Problem is not that I don't get the XML. My Problem is that the parser won't start.. I edited the code.</p> <p>EDIT2: The output from the response is:</p> <pre><code>2013-11-18 23:52:16.008 University[17210:70b] Response: &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN </code></pre> <p>So it seems like it worked, but the problem is the encoding of this into a NSData instance that I need to initialize my parser.</p> <p>EDIT3:</p> <p>After implementing the parser:parseErrorOccurred I got the following error in the Console:</p> <pre><code>2013-11-19 08:58:26.190 University[17458:70b] ERROR while parsing: The operation couldn’t be completed. (NSXMLParserErrorDomain error 65.) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload