Text encoding problem between NSImage, NSData, and NSXMLDocument

Posted by andyvn22 on Stack Overflow See other posts from Stack Overflow or by andyvn22
Published on 2010-04-03T23:13:52Z Indexed on 2010/04/03 23:23 UTC
Read the original article Hit count: 394

Filed under:
|
|
|

I'm attempting to take an NSImage and convert it to a string which I can write in an XML document.

My current attempt looks something like this:

[xmlDocument setCharacterEncoding: @"US-ASCII"];

NSData* data = [image TIFFRepresentation];
NSString* string = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];

//Put string inside of NSXMLElement, write out NSXMLDocument.

Reading back in looks something like this:

NSXMLDocument* newXMLDocument = [[NSXMLDocument alloc] initWithData:data options:0 error:outError];
//Here's where it fails. I get:
//Error Domain=NSXMLParserErrorDomain Code=9 UserInfo=0x100195310 "Line 7: Char 0x0 out of allowed range"

I assume I'm missing something basic. What's up with this encoding issue?

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about nsdata