diff --git a/XMLReader.m b/XMLReader.m index 754c95a..57fd27e 100644 --- a/XMLReader.m +++ b/XMLReader.m @@ -30,21 +30,23 @@ @implementation XMLReader + (NSDictionary *)dictionaryForXMLData:(NSData *)data error:(NSError **)error { - XMLReader *reader = [[XMLReader alloc] initWithError:error]; - NSDictionary *rootDictionary = [reader objectWithData:data options:0]; - return rootDictionary; + return [[self class] dictionaryForXMLData:data options:0 error:error]; } + (NSDictionary *)dictionaryForXMLString:(NSString *)string error:(NSError **)error { NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding]; - return [XMLReader dictionaryForXMLData:data error:error]; + return [XMLReader dictionaryForXMLData:data options:0 error:error]; } + (NSDictionary *)dictionaryForXMLData:(NSData *)data options:(XMLReaderOptions)options error:(NSError **)error { XMLReader *reader = [[XMLReader alloc] initWithError:error]; NSDictionary *rootDictionary = [reader objectWithData:data options:options]; + if (!rootDictionary && error) + { + *error = reader.errorPointer; + } return rootDictionary; } @@ -59,10 +61,10 @@ + (NSDictionary *)dictionaryForXMLString:(NSString *)string options:(XMLReaderOp - (id)initWithError:(NSError **)error { - self = [super init]; + self = [super init]; if (self) { - self.errorPointer = *error; + self.errorPointer = (error ? *error : nil); } return self; }