-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alan Yeh
committed
Jul 30, 2016
0 parents
commit 5435467
Showing
36 changed files
with
1,808 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# OS X | ||
.DS_Store | ||
|
||
# Xcode | ||
build/ | ||
*.pbxuser | ||
!default.pbxuser | ||
*.mode1v3 | ||
!default.mode1v3 | ||
*.mode2v3 | ||
!default.mode2v3 | ||
*.perspectivev3 | ||
!default.perspectivev3 | ||
xcuserdata/ | ||
*.xccheckout | ||
profile | ||
*.moved-aside | ||
DerivedData | ||
*.hmap | ||
*.ipa | ||
|
||
# Bundler | ||
.bundle | ||
|
||
Carthage | ||
# We recommend against adding the Pods directory to your .gitignore. However | ||
# you should judge for yourself, the pros and cons are mentioned at: | ||
# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control | ||
# | ||
# Note: if you ignore the Pods directory, make sure to uncomment | ||
# `pod install` in .travis.yml | ||
# | ||
Pods/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
osx_image: xcode7.3 | ||
language: objective-c | ||
|
||
branches: | ||
only: | ||
- master | ||
|
||
before_install: | ||
- git clone https://github.com/alan-yeh/CI.git | ||
- cp CI/cocoapods/* ./ | ||
- rm -rf CI | ||
- rm example.travis.yml | ||
|
||
install: | ||
- bundle install | ||
- pod install --project-directory=Example | ||
|
||
script: | ||
- bundle exec rake pod:lint --quiet | ||
|
||
after_success: | ||
- bundle exec rake pod:tag --quiet | ||
|
||
# Generate your secure token with the travis gem: | ||
# get Github token from your Travis CI profile page | ||
# gem install travis | ||
# GH_TOKEN from https://github.com/settings/tokens | ||
env: | ||
global: | ||
# travis encrypt 'GH_TOKEN=YOUR_TOKEN' | ||
- secure: "OyZ6+UJGdRbY2L1uuICNaNW9dWGbpAqRHEQ5OOBFIfapt6VVDQ67cGvmzjfqwriOmfRAPRmDbcB+dnVted941Mdv9aaCeBycSV8bZxZx9UnqDsKdvseMgtd1xLY09xgO+yvCdoVs4jqI/6kyiKEMClW7Ihys9bDXWkFmE4ilDzTFad/ZLqvNVOjc+NMLOPsEJtGN2J28ZM5h4dUT82ZKKc3a7SYBvzScDL1QLW50Qx2jQFZ8VnKO8z/bgONkU8c7N/gOEwV3QI3jh0U7+H5pbi3rGsvAXNcGf4wV41tv5k8ABRuom1tIydDXrsWHzax7YxZJ8E/6IHOCcUKFipjOzI7nFazNmaoNnyrY2ybMSngcFoqKF9m+9ZT+QgRx0NN0QJzW+OwmvgDHB5oQU5dgAsIdFcyqMoHt+rvuQ9sYr98kLvEfwUbj7IRwULN9oyDG6L12I6OZ53yxvXMRjEYJJeDyZYFOcYS6c5b2tg4glx0k2HeP/qPPr340riABfWYxSMVaOV+/Y5YnKWoxtqX+7VsPDDMrSL9OfR/ediUXHLSSfN/wweQTjniWORMYq96FwYbGJWkehJk5g68FFzgcDXUsMdrQXRn2L5PL2qe3dsVNbWHgwpDdp3/UW53tjOF/i0BqNBzXDz8fkex8UYZUMr8BHcbCNgAGAyohiRAbT9I=" | ||
#- PROJECT: AYPromise | ||
- GH_USER: alan-yeh | ||
#- GH_NAME: alan-yeh | ||
- GH_EMAIL: [email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# | ||
# Be sure to run `pod lib lint AYXML.podspec' to ensure this is a | ||
# valid spec before submitting. | ||
# | ||
# Any lines starting with a # are optional, but their use is encouraged | ||
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html | ||
# | ||
|
||
Pod::Spec.new do |s| | ||
s.name = 'AYXML' | ||
s.version = '1.0.0' | ||
s.summary = 'Simple framework to access XML.' | ||
|
||
s.homepage = 'https://github.com/alan-yeh/AYXML' | ||
s.license = { :type => 'MIT', :file => 'LICENSE' } | ||
s.author = { 'Alan Yeh' => '[email protected]' } | ||
s.source = { :git => 'https://github.com/alan-yeh/AYXML.git', :tag => s.version.to_s } | ||
|
||
s.ios.deployment_target = '6.0' | ||
|
||
s.source_files = 'AYXML/Classes/**/*' | ||
end |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// AYXML.h | ||
// AYXML | ||
// | ||
// Created by Alan Yeh on 16/3/2. | ||
// Copyright © 2016年 Alan Yeh. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
#import <AYXML/AYXMLDocument.h> | ||
#import <AYXML/AYXMLElement.h> | ||
#import <AYXML/AYXMLAttribute.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// AYXMLAttribute.h | ||
// AYXML | ||
// | ||
// Created by Alan Yeh on 16/3/2. | ||
// Copyright © 2016年 Alan Yeh. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface AYXMLAttribute : NSObject | ||
@property (nonatomic, copy) NSString *name; | ||
@property (nonatomic, copy) NSString *value; | ||
|
||
+ (instancetype)attributeWithName:(NSString *)name andValue:(NSString *)value; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// AYXMLAttribute.m | ||
// AYXML | ||
// | ||
// Created by Alan Yeh on 16/3/2. | ||
// Copyright © 2016年 Alan Yeh. All rights reserved. | ||
// | ||
|
||
#import "AYXMLAttribute.h" | ||
|
||
@implementation AYXMLAttribute | ||
+ (instancetype)attributeWithName:(NSString *)name andValue:(NSString *)value{ | ||
NSParameterAssert(name.length > 0); | ||
AYXMLAttribute *newInstance = [AYXMLAttribute new]; | ||
newInstance.name = name; | ||
newInstance.value = value ?: @""; | ||
return newInstance; | ||
} | ||
|
||
- (NSString *)description{ | ||
return [NSString stringWithFormat:@"%@=\"%@\"", self.name, self.value]; | ||
} | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// AYXMLDefines.h | ||
// AYXML | ||
// | ||
// Created by Alan Yeh on 16/3/3. | ||
// Copyright © 2016年 Alan Yeh. All rights reserved. | ||
// | ||
|
||
#ifndef AYXMLDefines_h | ||
#define AYXMLDefines_h | ||
|
||
#if defined(__cplusplus) | ||
#define AYXML_EXTERN extern "C" | ||
#else | ||
#define AYXML_EXTERN extern | ||
#endif | ||
|
||
#define AYXML_EXTERN_STRING(KEY, COMMENT) AYXML_EXTERN NSString * const _Nonnull KEY; | ||
#define AYXML_EXTERN_STRING_IMP(KEY) NSString * const KEY = @#KEY; | ||
#define AYXML_EXTERN_STRING_IMP2(KEY, VAL) NSString * const KEY = VAL; | ||
|
||
#define AYXML_ENUM_OPTION(ENUM, VAL, COMMENT) ENUM = VAL | ||
|
||
#define AYXML_API_UNAVAILABLE(INFO) __attribute__((unavailable(INFO))) | ||
|
||
#endif /* AYXMLDefines_h */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// AYXMLDocument.h | ||
// AYXML | ||
// | ||
// Created by Alan Yeh on 16/3/2. | ||
// Copyright © 2016年 Alan Yeh. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@class AYXMLElement; | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
@interface AYXMLDocument : NSObject | ||
@property (nonatomic, nullable, strong) NSString *xmlEncoding; | ||
@property (nonatomic, nullable, strong) AYXMLElement *rootElement; | ||
|
||
+ (AYXMLDocument *)documentWithText:(NSString *)text; | ||
+ (AYXMLDocument *)documentWithText:(NSString *)text error:(NSError **)error; | ||
|
||
+ (AYXMLDocument *)documentWithData:(NSData *)data; | ||
+ (AYXMLDocument *)documentWithData:(NSData *)data error:(NSError **)error; | ||
@end | ||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// | ||
// AYXMLDocument.m | ||
// AYXML | ||
// | ||
// Created by Alan Yeh on 16/3/2. | ||
// Copyright © 2016年 Alan Yeh. All rights reserved. | ||
// | ||
|
||
#import "AYXMLDocument.h" | ||
#import "AYXMLElement.h" | ||
#import "AYXMLAttribute.h" | ||
|
||
@interface _AYXMLDelegate : NSObject<NSXMLParserDelegate> | ||
@property (nonatomic, strong) AYXMLDocument *result; | ||
@property (nonatomic, strong) NSError *error; | ||
@end | ||
|
||
@implementation AYXMLDocument | ||
+ (AYXMLDocument *)documentWithText:(NSString *)text{ | ||
return [self documentWithData:[text dataUsingEncoding:NSUTF8StringEncoding] error:nil]; | ||
} | ||
|
||
+ (AYXMLDocument *)documentWithText:(NSString *)text error:(NSError *__autoreleasing *)error{ | ||
return [self documentWithData:[text dataUsingEncoding:NSUTF8StringEncoding] error:error]; | ||
} | ||
|
||
+ (AYXMLDocument *)documentWithData:(NSData *)data{ | ||
NSError *error; | ||
AYXMLDocument *doc = [self documentWithData:data error:&error]; | ||
if (error != nil) { | ||
@throw error; | ||
} | ||
return doc; | ||
} | ||
|
||
+ (AYXMLDocument *)documentWithData:(NSData *)data error:(NSError * _Nullable __autoreleasing *)error{ | ||
NSParameterAssert(data.length > 0); | ||
_AYXMLDelegate *delegate = [_AYXMLDelegate new]; | ||
NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data]; | ||
parser.delegate = delegate; | ||
// parser.shouldProcessNamespaces = YES; | ||
// parser.shouldReportNamespacePrefixes = YES; | ||
if ([parser parse]) { | ||
return [delegate result]; | ||
}else{ | ||
if (error != NULL) { | ||
*error = delegate.error; | ||
} | ||
return nil; | ||
} | ||
} | ||
|
||
- (NSString *)description{ | ||
return [self.rootElement description]; | ||
} | ||
|
||
- (NSString *)debugDescription{ | ||
return [self.rootElement debugDescription]; | ||
} | ||
@end | ||
|
||
@implementation _AYXMLDelegate{ | ||
AYXMLElement *_currentElement; | ||
} | ||
- (void)parserDidStartDocument:(NSXMLParser *)parser{ | ||
_result = [[AYXMLDocument alloc] init]; | ||
} | ||
|
||
- (void)parserDidEndDocument:(NSXMLParser *)parser{ | ||
[_currentElement fixContent]; | ||
_result.rootElement = _currentElement; | ||
} | ||
|
||
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary<NSString *,NSString *> *)attributeDict{ | ||
|
||
AYXMLElement *element = [[AYXMLElement alloc] initWithName:elementName]; | ||
|
||
element.parent = _currentElement; | ||
[_currentElement.elements addObject:element]; | ||
_currentElement = element; | ||
|
||
for (NSString *key in attributeDict) { | ||
[element.attributes addObject:[AYXMLAttribute attributeWithName:key andValue:attributeDict[key]]]; | ||
} | ||
} | ||
|
||
- (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock{ | ||
[_currentElement.content appendString:[[NSString alloc] initWithData:CDATABlock encoding:NSUTF8StringEncoding]]; | ||
} | ||
|
||
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{ | ||
[_currentElement.content appendString:string]; | ||
} | ||
|
||
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{ | ||
if (_currentElement.parent != nil) { | ||
_currentElement = _currentElement.parent; | ||
} | ||
} | ||
|
||
- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError{ | ||
self.result = nil; | ||
self.error = parseError; | ||
} | ||
|
||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// | ||
// AYXMLElement.h | ||
// AYXML | ||
// | ||
// Created by Alan Yeh on 16/3/2. | ||
// Copyright © 2016年 Alan Yeh. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <AYXML/AYXMLDefines.h> | ||
|
||
@class AYXMLAttribute; | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
@interface AYXMLElement : NSObject | ||
- (instancetype)init AYXML_API_UNAVAILABLE(""); | ||
+ (instancetype)new AYXML_API_UNAVAILABLE(""); | ||
|
||
- (instancetype)initWithName:(NSString *)name; | ||
+ (instancetype)elementWithName:(NSString *)name; | ||
|
||
- (instancetype)initWithName:(NSString *)name andContent:(NSString *)content; | ||
+ (instancetype)elementWithName:(NSString *)name andContent:(NSString *)content; | ||
|
||
@property (nonatomic, copy) NSString *name; | ||
|
||
@property (nonatomic, strong) AYXMLElement *parent; | ||
|
||
@property (nonatomic, strong) NSMutableArray<AYXMLElement *> *elements; | ||
- (instancetype)addElement:(AYXMLElement *)element; | ||
|
||
@property (nonatomic, strong) NSMutableArray<AYXMLAttribute *> *attributes; | ||
- (instancetype)addAttribute:(AYXMLAttribute *)attribute; | ||
|
||
@property (nonatomic, strong) NSMutableString *content; | ||
|
||
- (nullable AYXMLElement *)elementWithName:(NSString *)name; | ||
- (NSArray<AYXMLElement *> *)elementsWithName:(NSString *)name; | ||
|
||
- (nullable AYXMLElement *)elementAtPath:(NSString *)keyPath; | ||
- (NSArray<AYXMLElement *> *)elementsAtPath:(NSString *)keyPath; | ||
|
||
- (nullable NSString *)attributeValue:(NSString *)attributeName; | ||
|
||
- (void)fixContent; | ||
@end | ||
|
||
AYXML_EXTERN AYXMLElement *AYXMLElementWithName(NSString *name); | ||
@interface AYXMLElement (Chain) | ||
- (AYXMLElement *)and; | ||
- (AYXMLElement *(^)(NSString *))addContent; | ||
- (AYXMLElement *(^)(NSString *, NSString *))addAttr; | ||
- (AYXMLElement *(^)(AYXMLElement *))addElement; | ||
- (AYXMLElement *(^)(NSArray<AYXMLElement *> *))addElements; | ||
@end | ||
NS_ASSUME_NONNULL_END |
Oops, something went wrong.