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

Revert dd_ prefix for additions #117

Merged
merged 1 commit into from
Oct 27, 2019
Merged
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
2 changes: 1 addition & 1 deletion KissXML.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'KissXML'
s.version = '5.3.0'
s.version = '5.3.1'
s.license = { :type => 'MIT', :file => 'LICENSE.txt' }
s.summary = 'A replacement for Cocoa\'s NSXML cluster of classes. Based on libxml.'
s.homepage = 'https://github.com/robbiehanson/KissXML'
Expand Down
38 changes: 10 additions & 28 deletions KissXML/Additions/DDXMLElementAdditions.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,20 @@
NS_ASSUME_NONNULL_BEGIN
@interface DDXMLElement (DDAdditions)

+ (nullable DDXMLElement *)dd_elementWithName:(NSString *)name xmlns:(NSString *)ns;
+ (nullable DDXMLElement *)elementWithName:(NSString *)name xmlns:(NSString *)ns;

- (nullable DDXMLElement *)dd_elementForName:(NSString *)name;
- (nullable DDXMLElement *)dd_elementForName:(NSString *)name xmlns:(NSString *)xmlns;
- (nullable DDXMLElement *)elementForName:(NSString *)name;
- (nullable DDXMLElement *)elementForName:(NSString *)name xmlns:(NSString *)xmlns;

@property (nonatomic, readwrite, nullable) NSString *dd_xmlns;
- (nullable NSString *)xmlns;
- (void)setXmlns:(NSString *)ns;

@property (nonatomic, readonly) NSString *dd_prettyXMLString;
@property (nonatomic, readonly) NSString *dd_compactXMLString;
- (NSString *)prettyXMLString;
- (NSString *)compactXMLString;

- (void)dd_addAttributeWithName:(NSString *)name stringValue:(NSString *)string;
- (void)addAttributeWithName:(NSString *)name stringValue:(NSString *)string;

@property (nonatomic, readonly) NSDictionary<NSString*,NSString*> *dd_attributesAsDictionary;
- (NSDictionary<NSString*,NSString*> *)attributesAsDictionary;

@end

@interface DDXMLElement (DDAdditionsDeprecated)

+ (nullable DDXMLElement *)elementWithName:(NSString *)name xmlns:(NSString *)ns DEPRECATED_MSG_ATTRIBUTE("use dd_elementWithName:xmlns: instead.");

- (nullable DDXMLElement *)elementForName:(NSString *)name DEPRECATED_MSG_ATTRIBUTE("use dd_elementForName: instead.");
- (nullable DDXMLElement *)elementForName:(NSString *)name xmlns:(NSString *)xmlns DEPRECATED_MSG_ATTRIBUTE("use dd_elementForName:xmlns: instead.");

- (nullable NSString *)xmlns DEPRECATED_MSG_ATTRIBUTE("use dd_xmlns instead.");
- (void)setXmlns:(NSString *)ns DEPRECATED_MSG_ATTRIBUTE("use setDd_xmlns: instead.");

- (NSString *)prettyXMLString DEPRECATED_MSG_ATTRIBUTE("use dd_prettyXMLString instead.");
- (NSString *)compactXMLString DEPRECATED_MSG_ATTRIBUTE("use dd_compactXMLString instead.");

- (void)addAttributeWithName:(NSString *)name stringValue:(NSString *)string DEPRECATED_MSG_ATTRIBUTE("use dd_addAttributeWithName:stringValue: instead.");

- (NSDictionary<NSString*,NSString*> *)attributesAsDictionary DEPRECATED_MSG_ATTRIBUTE("use dd_attributesAsDictionary instead.");

@end
NS_ASSUME_NONNULL_END
NS_ASSUME_NONNULL_END
60 changes: 10 additions & 50 deletions KissXML/Additions/DDXMLElementAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ @implementation DDXMLElement (DDAdditions)
/**
* Quick method to create an element
**/
+ (DDXMLElement *)dd_elementWithName:(NSString *)name xmlns:(NSString *)ns
+ (DDXMLElement *)elementWithName:(NSString *)name xmlns:(NSString *)ns
{
DDXMLElement *element = [DDXMLElement elementWithName:name];
element.dd_xmlns = ns;
[element setXmlns:ns];
return element;
}

/**
* This method returns the first child element for the given name.
* If no child element exists for the given name, returns nil.
**/
- (DDXMLElement *)dd_elementForName:(NSString *)name
- (DDXMLElement *)elementForName:(NSString *)name
{
NSArray *elements = [self elementsForName:name];
if([elements count] > 0)
Expand Down Expand Up @@ -54,7 +54,7 @@ - (DDXMLElement *)dd_elementForName:(NSString *)name
* This method returns the first child element for the given name and given xmlns.
* If no child elements exist for the given name and given xmlns, returns nil.
**/
- (DDXMLElement *)dd_elementForName:(NSString *)name xmlns:(NSString *)xmlns
- (DDXMLElement *)elementForName:(NSString *)name xmlns:(NSString *)xmlns
{
NSArray *elements = [self elementsForLocalName:name URI:xmlns];
if([elements count] > 0)
Expand All @@ -71,12 +71,12 @@ - (DDXMLElement *)dd_elementForName:(NSString *)name xmlns:(NSString *)xmlns
* Returns the common xmlns "attribute", which is only accessible via the namespace methods.
* The xmlns value is often used in jabber elements.
**/
- (NSString *)dd_xmlns
- (NSString *)xmlns
{
return [[self namespaceForPrefix:@""] stringValue];
}

- (void)setDd_xmlns:(NSString *)ns
- (void)setXmlns:(NSString *)ns
{
// If you use setURI: then the xmlns won't be displayed in the XMLString.
// Adding the namespace this way works properly.
Expand All @@ -89,31 +89,31 @@ - (void)setDd_xmlns:(NSString *)ns
/**
* Shortcut to get a pretty (formatted) string representation of the element.
**/
- (NSString *)dd_prettyXMLString
- (NSString *)prettyXMLString
{
return [self XMLStringWithOptions:(DDXMLNodePrettyPrint | DDXMLNodeCompactEmptyElement)];
}

/**
* Shortcut to get a compact string representation of the element.
**/
- (NSString *)dd_compactXMLString
- (NSString *)compactXMLString
{
return [self XMLStringWithOptions:DDXMLNodeCompactEmptyElement];
}

/**
* Shortcut to avoid having to manually create a DDXMLNode everytime.
**/
- (void)dd_addAttributeWithName:(NSString *)name stringValue:(NSString *)string
- (void)addAttributeWithName:(NSString *)name stringValue:(NSString *)string
{
[self addAttribute:[DDXMLNode attributeWithName:name stringValue:string]];
}

/**
* Returns all the attributes as a dictionary.
**/
- (NSDictionary *)dd_attributesAsDictionary
- (NSDictionary *)attributesAsDictionary
{
NSArray *attributes = [self attributes];
NSMutableDictionary *result = [NSMutableDictionary dictionaryWithCapacity:[attributes count]];
Expand All @@ -129,43 +129,3 @@ - (NSDictionary *)dd_attributesAsDictionary
}

@end

@implementation DDXMLElement (DDAdditionsDeprecated)

+ (nullable DDXMLElement *)elementWithName:(NSString *)name xmlns:(NSString *)ns {
return [self dd_elementWithName:name xmlns:ns];
}

- (nullable DDXMLElement *)elementForName:(NSString *)name {
return [self dd_elementForName:name];
}

- (nullable DDXMLElement *)elementForName:(NSString *)name xmlns:(NSString *)xmlns {
return [self dd_elementForName:name xmlns:xmlns];
}

- (nullable NSString *)xmlns {
return [self dd_xmlns];
}

- (void)setXmlns:(NSString *)ns {
[self setDd_xmlns:ns];
}

- (NSString *)prettyXMLString {
return [self dd_prettyXMLString];
}

- (NSString *)compactXMLString {
return [self dd_compactXMLString];
}

- (void)addAttributeWithName:(NSString *)name stringValue:(NSString *)string {
return [self dd_addAttributeWithName:name stringValue:string];
}

- (NSDictionary<NSString*,NSString*> *)attributesAsDictionary {
return [self dd_attributesAsDictionary];
}

@end