diff --git a/KissXML/DDXMLNode.h b/KissXML/DDXMLNode.h index eafde87f..818f97d4 100644 --- a/KissXML/DDXMLNode.h +++ b/KissXML/DDXMLNode.h @@ -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; @@ -138,4 +140,4 @@ NS_ASSUME_NONNULL_BEGIN //- (NSArray *)objectsForXQuery:(NSString *)xquery error:(NSError **)error; @end -NS_ASSUME_NONNULL_END \ No newline at end of file +NS_ASSUME_NONNULL_END diff --git a/KissXML/DDXMLNode.m b/KissXML/DDXMLNode.m index f9d5ffdb..dc52865e 100644 --- a/KissXML/DDXMLNode.m +++ b/KissXML/DDXMLNode.m @@ -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. *