سؤال

I have an IOS app where I need to parse an xml file and I've been working with NSXMLParser. I have some xml data that about 8kbytes and Im getting this error, but Im parsing smaller files without an issue. I've tried searching and I couldn't find anyone else with this problem in IOS. Is this a limitation of NSXMLParser and I need to use a different library or is there some property that has to be set to allow for larger data?

Any help would be appreciated.

EDIT: Here is the file exactly as I'm retrieving from my web service: https://www.dropbox.com/s/3436w653reyybpb/File.xml

Here is the code Im using:

// XML.m
- (id)parseXml:(NSData *)data
{
    NSXMLParser *xml = [[NSXMLParser alloc] initWithData:data];
    xml.delegate = self;
    results = [[NSMutableArray alloc] init];
    error = nil;
    [xml parse];
    if (error) return error;
    return results;
}
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI: (NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
    [results addObject:attributeDict];
}
- (void) parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError
{
    error = parseError;
}

The code isn't even reaching the didStartElement delegate method, it's just going right to the parseErrorOccured. The data thats being passed is the file contents that I supplied.

هل كانت مفيدة؟

المحلول

The xml:

<?xml version="1.0" encoding="utf-16"?>

specifies that it is utf-16 but it is actually utf-8

نصائح أخرى

As Zaph said, the issue is that it is not utf-16. In the future, if the NSXMLParser error message is not clear enough, you can try running this through xmllint at the Terminal command line. In this case, it reports:

$ xmllint File.xml 
File.xml:1: parser error : Document labelled UTF-16 but has UTF-8 content
<?xml version="1.0" encoding="utf-16"?><Response Error=""><RX RxNumber="11684600
                                     ^
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top