Martin gave you an example of what you could do to log the characters. Or you could store it in a NSData
and see it in hex:
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
NSLog(@"%@", data);
Or, if you just want to see the control characters in XML hex, but leave printable characters unchanged, you can use CFStringTransform
:
NSMutableString *mutableString = [string mutableCopy];
CFStringTransform((__bridge CFMutableStringRef)mutableString, NULL, kCFStringTransformToXMLHex, NO);
But in answer to the question about what the parser stores when it encounters <tag></tag>
, it all depends upon how you implemented it (and show us what you did if you have questions). But most of us would alloc
and init
the NSMutableString
in didStartElement
, we'd append string in foundCharacters
, and then store it in our model in didEndElement
. In that scenario, that empty tag would yield a zero length mutable string (e.g. @""
, except a mutable string). How did you conclude it was not @""
? If you checked for [string isEqualToString:@""]
, that should have worked fine.
By the way, if you want to trim extra whitespace from your result, you could, in didEndElement
, do something like:
self.modelObject.someStringProperty = [self.parsedString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
That way, if there were any extra spaces or newline characters, they'd get stripped out.