Index: src/OFXMLAttribute.m ================================================================== --- src/OFXMLAttribute.m +++ src/OFXMLAttribute.m @@ -69,6 +69,25 @@ - (OFString*)stringValue { return [[stringValue copy] autorelease]; } + +- (BOOL)isEqual: (id)object +{ + OFXMLAttribute *other; + + if (![object isKindOfClass: [OFXMLAttribute class]]) + return NO; + + other = object; + + if (![other->name isEqual: name]) + return NO; + if (other->ns != ns && ![other->ns isEqual: ns]) + return NO; + if (![other->stringValue isEqual: stringValue]) + return NO; + + return YES; +} @end Index: src/OFXMLElement.m ================================================================== --- src/OFXMLElement.m +++ src/OFXMLElement.m @@ -756,10 +756,45 @@ [ret addObject: children_c[i]]; } return ret; } + +- (BOOL)isEqual: (id)object +{ + OFXMLElement *other; + + if (![object isKindOfClass: [OFXMLElement class]]) + return NO; + + other = object; + + if (other->name != name && ![other->name isEqual: name]) + return NO; + if (other->ns != ns && ![other->ns isEqual: ns]) + return NO; + if (other->defaultNamespace != defaultNamespace && + ![other->defaultNamespace isEqual: defaultNamespace]) + return NO; + if (other->attributes != attributes && + ![other->attributes isEqual: attributes]) + return NO; + if (other->namespaces != namespaces && + ![other->namespaces isEqual: namespaces]) + return NO; + if (other->children != children && ![other->children isEqual: children]) + return NO; + if (other->characters != characters && + ![other->characters isEqual: characters]) + return NO; + if (other->cdata != cdata && ![other->cdata isEqual: cdata]) + return NO; + if (other->comment != comment && ![other->comment isEqual: comment]) + return NO; + + return YES; +} - (void)dealloc { [name release]; [ns release]; Index: tests/OFXMLElementTests.m ================================================================== --- tests/OFXMLElementTests.m +++ tests/OFXMLElementTests.m @@ -127,8 +127,14 @@ (a = [elem[2] elementsForName: @"bar" namespace: @"urn:objfw:test"]) && [a count] == 1 && [[[a firstObject] XMLString] isEqual: @""]) + TEST(@"-[isEqual:]", + [[OFXMLElement elementWithXMLString: @""] isEqual: + [OFXMLElement elementWithXMLString: @""]] && + [[OFXMLElement elementWithXMLString: @""] isEqual: + [OFXMLElement elementWithXMLString: @""]]) + [pool drain]; } @end