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

Feature/add isdescendant and isancestor method #75

Open
wants to merge 2 commits 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
4 changes: 3 additions & 1 deletion KissXML/DDXMLNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ NS_ASSUME_NONNULL_BEGIN
@property (nullable, readonly, copy) DDXMLNode *nextNode;

- (void)detach;
- (BOOL)isDescendant:(DDXMLNode *)of;
- (BOOL)isAncestor:(DDXMLNode *)of;

@property (nullable, readonly, copy) NSString *XPath;

Expand Down Expand Up @@ -138,4 +140,4 @@ NS_ASSUME_NONNULL_BEGIN
//- (NSArray *)objectsForXQuery:(NSString *)xquery error:(NSError **)error;

@end
NS_ASSUME_NONNULL_END
NS_ASSUME_NONNULL_END
21 changes: 21 additions & 0 deletions KissXML/DDXMLNode.m
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,27 @@ - (DDXMLNode *)nextNode
return nil;
}

/**
* Returns if node is descendant of the other node.
**/
- (BOOL)isDescendant:(DDXMLNode *)of
{
if (self.parent == nil)
return NO;
if (self.parent == of)
return YES;
else
return [self.parent isDescendant:of];
}

/**
* Returns if node is ancestor of the other node.
**/
- (BOOL)isAncestor:(DDXMLNode *)of
{
return [of isDescendant:self];
}

/**
* Detaches the receiver from its parent node.
*
Expand Down