I'm using NSXMLParser to parse an xml from a url (my code is almost exactly the same as here)
Some of the elements contain special characters like "á" which causes a word lik ándre to split into two (á and ndre).
Here is my loadXMLByURL
-(id) loadXMLByURL:(NSString *)urlString{
tickets = [[NSMutableArray alloc] init];
NSURL *url = [NSURL URLWithString:urlString];
NSData *data = [[NSData alloc] initWithContentsOfURL:url];
parser = [[NSXMLParser alloc] initWithData:data];
parser.delegate = self;
[parser parse];
return self;}
I'm pretty sure it's because the encoding is not set (I think it needs to be NSUTF8StringEncoding) but I'm not sure where/how to apply it.
[UPDATE] Rest of my code...
- (void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementname namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if ([elementname isEqualToString:@"ticket"])
{
currentTicket = [Ticket alloc];
}
}
- (void) parser:(NSXMLParser *)parser didEndElement:(NSString *)elementname namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if ([elementname isEqualToString:@"name"])
{
currentTicket.name = currentNodeContent;
}
else if ([elementname isEqualToString:@"title"])
{
currentTicket.title = currentNodeContent;
}
else if ([elementname isEqualToString:@"status"])
{
currentTicket.status = currentNodeContent;
}
else if ([elementname isEqualToString:@"ticket"])
{
[tickets addObject:currentTicket];
[currentTicket release];
currentTicket = nil;
[currentNodeContent release];
currentNodeContent = nil;
}
}
- (void) parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
currentNodeContent = (NSMutableString *) [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}
[UPDATE 2] Sample xml...
<RB>
<list>
<ticket>
<name>Andrew Ford</name>
<title>3rd release</title>
<status>1</status>
</ticket>
<ticket>
<name>David Jenkins</name>
<title>3rd release</title>
<status>0</status>
</ticket>
<ticket>
<name>Luis gomez ándre</name>
<title>3rd release</title>
<status>1</status>
</ticket>
</list>
</RB>