0
votes

hi friends
this is my xml file

1)
<sDescrizione>Crociera nei fiordi</sDescrizione>

2)
<sDescrizione>Fiat 500</sDescrizione>

3)
<sDescrizione>Orologio donna Glam sport Tissot</sDescrizione>

4)
<sDescrizione>Buoni La Rinascente 1000€</sDescrizione>

5)
<sDescrizione>Buoni Unieuro 1000€</sDescrizione>

this is what i want to retrieve from that xml file using CXML parsing method the first 3 title are successfully retrived but when it comes at 4th it gives me error in my console like this

Entity: line 80: parser error : Input is not proper UTF-8, indicate encoding !

Bytes: 0x80 0x5D 0x5D 0x3E

  <sDescrizione><![CDATA[Buoni La Rinascente 1000\200]]></sDescrizione>
                                                 ^

this is my retrieving code: NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; CXMLDocument *xmlParser = [[[CXMLDocument alloc] initWithData:data options:0 error:nil] autorelease];

NSArray *resultNodes = [xmlParser nodesForXPath:@"//premio" error:nil];

for (CXMLElement *resultElement in resultNodes) {

    for (int j=0; j<[resultElement childCount]; j++) {
        NSString *tagName = [NSString stringWithString:[[resultElement childAtIndex:j] name]];


        if ([tagName isEqualToString:@"sDescrizione"])
        {
            NSString *temp = [[resultElement childAtIndex:j] stringValue];
            [catArray addObject:temp];
        }
        else if([tagName isEqualToString:@"idPremioSodexho"])
        {
            NSString *trmp = [[resultElement childAtIndex:j] stringValue];

        }
    }


}
2

2 Answers

1
votes

Looks like the XML file is not in UTF-8 and CXMLDocument is assuming it is. When it hits the € sign its crashing. Set the correct encoding in the header of the XML file. If the XML file is encoded with ISO 8859-1 then set the header like:

<?xml version="1.0" encoding="ISO-8859-1"?>

This will allow CXMLDocument to correctly interpret the characters/codepage of your XML document.

0
votes

I think you are facing the problem due to invalid Character-sets.

See, here is the line of code that you have used.

 // when you don't specify any encoding, TouchXML will use NSUTF8Encoding as default
 // which may lead to some problems 
 CXMLDocument *xmlParser = [[[CXMLDocument alloc] initWithData:data options:0 error:nil] autorelease];

 // So, I recommend you to use following line of code, which may not lead you with messy situations.
 CXMLDocument *doc = [[CXMLDocument alloc] initWithData:[request responseData] encoding:[request responseEncoding] options:0 error:nil];