Note that there are some explanatory texts on larger screens.

plurals
  1. PONSXMLParser with UTF8 Data
    primarykey
    data
    text
    <p>I'm having a really hard time trying to figure this out and would really appreciate any help.</p> <p>I'm trying to parse a utf 8 string with NSXMLParser but it won't work.</p> <p>here is my string</p> <p><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;host&gt;&lt;type&gt;mac&lt;/type&gt;&lt;port&gt;62181&lt;/port&gt;&lt;address&gt;192.168.1.159&lt;/address&gt;&lt;hostname&gt;Samuel’s%20Mac%20Book&lt;/hostname&gt;&lt;username&gt;samuelw&lt;/username&gt;&lt;/host&gt;</code></p> <p>and here the parsing code </p> <pre><code>- (void) parse:(NSString*)XMLEncodedString withLength:(int)l_length { #ifndef NDEBUG NSLog(@"Received lookup %@",XMLEncodedString); #endif NSData* data=[XMLEncodedString dataUsingEncoding:NSUTF8StringEncoding]; NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data]; [parser setDelegate:self]; // The parser calls methods in this class [parser setShouldProcessNamespaces:NO]; // We don't care about namespaces [parser setShouldReportNamespacePrefixes:NO]; // [parser setShouldResolveExternalEntities:NO]; // We just want data, no other stuff [parser parse]; // Parse that data.. [parser release]; } </code></pre> <p>the XMLEncodedString is constructed like this </p> <pre><code>- (void) checkForReceive { //NSLog(@"listener: waiting to recvfrom...\n"); addr_len = sizeof their_addr; if ((numbytes = recvfrom(sockfd, buf, MAXBUFLEN-1 , 0, (struct sockaddr *)&amp;their_addr, &amp;addr_len)) == -1) { perror("recvfrom"); return; } buf[numbytes] = '\0'; NSString * string = [[NSString alloc] initWithUTF8String:buf]; [self parse:string withLength:numbytes]; [string release]; } </code></pre> <p>my problem is coming from the Unicode Character 'RIGHT SINGLE QUOTATION MARK' (U+2019) that I have in my string and I am getting this error:</p> <p>2010-07-19 17:13:35.734 SwypeSendForMac2[34354:4233] Error Domain=NSXMLParserErrorDomain Code=73 "The operation couldn’t be completed. (NSXMLParserErrorDomain error 73.)" 2010-07-19 17:13:35.736 SwypeSendForMac2[34354:4233] Error Domain=NSXMLParserErrorDomain Code=76 "The operation couldn’t be completed. (NSXMLParserErrorDomain error 76.)"</p>
    singulars
    1. This table or related slice is empty.
    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