Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add error feedback #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Tests/.DS_Store
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0710"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "013F12EF154BB2EB00F50A5E"
BuildableName = "XMLTest.app"
BlueprintName = "XMLTest"
ReferencedContainer = "container:XMLTest.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "013F12EF154BB2EB00F50A5E"
BuildableName = "XMLTest.app"
BlueprintName = "XMLTest"
ReferencedContainer = "container:XMLTest.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "013F12EF154BB2EB00F50A5E"
BuildableName = "XMLTest.app"
BlueprintName = "XMLTest"
ReferencedContainer = "container:XMLTest.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "013F12EF154BB2EB00F50A5E"
BuildableName = "XMLTest.app"
BlueprintName = "XMLTest"
ReferencedContainer = "container:XMLTest.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>XMLTest.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>013F12EF154BB2EB00F50A5E</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
9 changes: 5 additions & 4 deletions XMLDictionary/XMLDictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@ static NSString *const XMLDictionaryAttributePrefix = @"_";

@property (nonatomic, assign) XMLDictionaryAttributesMode attributesMode;
@property (nonatomic, assign) XMLDictionaryNodeNameMode nodeNameMode;
@property (nonatomic, strong) NSError *error;

- (NSDictionary *)dictionaryWithParser:(NSXMLParser *)parser;
- (NSDictionary *)dictionaryWithData:(NSData *)data;
- (NSDictionary *)dictionaryWithString:(NSString *)string;
- (NSDictionary *)dictionaryWithFile:(NSString *)path;
- (NSDictionary *)dictionaryWithString:(NSString *)string error:(NSError **)error;
- (NSDictionary *)dictionaryWithFile:(NSString *)path error:(NSError **)error;
- (NSDictionary *)dictionaryWithParser:(NSXMLParser *)parser error:(NSError **)error;
- (NSDictionary *)dictionaryWithData:(NSData *)data error:(NSError **)error;

@end

Expand Down
28 changes: 17 additions & 11 deletions XMLDictionary/XMLDictionary.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,33 +94,34 @@ - (id)copyWithZone:(NSZone *)zone
return copy;
}

- (NSDictionary *)dictionaryWithParser:(NSXMLParser *)parser
- (NSDictionary *)dictionaryWithParser:(NSXMLParser *)parser error:(NSError *__autoreleasing *)error
{
[parser setDelegate:self];
[parser parse];
id result = _root;
_root = nil;
_stack = nil;
_text = nil;
*error = self.error;
return result;
}

- (NSDictionary *)dictionaryWithData:(NSData *)data
- (NSDictionary *)dictionaryWithData:(NSData *)data error:(NSError *__autoreleasing *)error
{
NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data];
return [self dictionaryWithParser:parser];
return [self dictionaryWithParser:parser error:error];
}

- (NSDictionary *)dictionaryWithString:(NSString *)string
- (NSDictionary *)dictionaryWithString:(NSString *)string error:(NSError *__autoreleasing *)error
{
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
return [self dictionaryWithData:data];
return [self dictionaryWithData:data error:error];
}

- (NSDictionary *)dictionaryWithFile:(NSString *)path
- (NSDictionary *)dictionaryWithFile:(NSString *)path error:(NSError *__autoreleasing *)error
{
NSData *data = [NSData dataWithContentsOfFile:path];
return [self dictionaryWithData:data];
return [self dictionaryWithData:data error:error];
}

+ (NSString *)XMLStringForNode:(id)node withNodeName:(NSString *)nodeName
Expand Down Expand Up @@ -359,6 +360,11 @@ - (void)parser:(__unused NSXMLParser *)parser foundCharacters:(NSString *)string
[self addText:string];
}

- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError {
self.error = parseError;
_root = nil;
}

- (void)parser:(__unused NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock
{
[self addText:[[NSString alloc] initWithData:CDATABlock encoding:NSUTF8StringEncoding]];
Expand Down Expand Up @@ -389,22 +395,22 @@ @implementation NSDictionary(XMLDictionary)

+ (NSDictionary *)dictionaryWithXMLParser:(NSXMLParser *)parser
{
return [[[XMLDictionaryParser sharedInstance] copy] dictionaryWithParser:parser];
return [[[XMLDictionaryParser sharedInstance] copy] dictionaryWithParser:parser error:nil];
}

+ (NSDictionary *)dictionaryWithXMLData:(NSData *)data
{
return [[[XMLDictionaryParser sharedInstance] copy] dictionaryWithData:data];
return [[[XMLDictionaryParser sharedInstance] copy] dictionaryWithData:data error:nil];
}

+ (NSDictionary *)dictionaryWithXMLString:(NSString *)string
{
return [[[XMLDictionaryParser sharedInstance] copy] dictionaryWithString:string];
return [[[XMLDictionaryParser sharedInstance] copy] dictionaryWithString:string error:nil];
}

+ (NSDictionary *)dictionaryWithXMLFile:(NSString *)path
{
return [[[XMLDictionaryParser sharedInstance] copy] dictionaryWithFile:path];
return [[[XMLDictionaryParser sharedInstance] copy] dictionaryWithFile:path error:nil];
}

- (NSDictionary *)attributes
Expand Down