Index: src/OFXMLAttribute.m
==================================================================
--- src/OFXMLAttribute.m
+++ src/OFXMLAttribute.m
@@ -106,10 +106,29 @@
- (OFString*)stringValue
{
return [[stringValue copy] autorelease];
}
+
+- (BOOL)isEqual: (id)object
+{
+ OFXMLAttribute *otherAttribute;
+
+ if (![object isKindOfClass: [OFXMLAttribute class]])
+ return NO;
+
+ otherAttribute = object;
+
+ if (![otherAttribute->name isEqual: name])
+ return NO;
+ if (otherAttribute->ns != ns && ![otherAttribute->ns isEqual: ns])
+ return NO;
+ if (![otherAttribute->stringValue isEqual: stringValue])
+ return NO;
+
+ return YES;
+}
- (OFXMLElement*)XMLElementBySerializing
{
OFAutoreleasePool *pool;
OFXMLElement *element;
Index: src/OFXMLElement.m
==================================================================
--- src/OFXMLElement.m
+++ src/OFXMLElement.m
@@ -936,10 +936,48 @@
[cArray[i]->name isEqual: elementName])
[ret addObject: cArray[i]];
return ret;
}
+
+- (BOOL)isEqual: (id)object
+{
+ OFXMLElement *otherElement;
+
+ if (![object isKindOfClass: [OFXMLElement class]])
+ return NO;
+
+ otherElement = object;
+
+ if (otherElement->name != name && ![otherElement->name isEqual: name])
+ return NO;
+ if (otherElement->ns != ns && ![otherElement->ns isEqual: ns])
+ return NO;
+ if (otherElement->defaultNamespace != defaultNamespace &&
+ ![otherElement->defaultNamespace isEqual: defaultNamespace])
+ return NO;
+ if (otherElement->attributes != attributes &&
+ ![otherElement->attributes isEqual: attributes])
+ return NO;
+ if (otherElement->namespaces != namespaces &&
+ ![otherElement->namespaces isEqual: namespaces])
+ return NO;
+ if (otherElement->children != children &&
+ ![otherElement->children isEqual: children])
+ return NO;
+ if (otherElement->characters != characters &&
+ ![otherElement->characters isEqual: characters])
+ return NO;
+ if (otherElement->CDATA != CDATA &&
+ ![otherElement->CDATA isEqual: CDATA])
+ return NO;
+ if (otherElement->comment != comment &&
+ ![otherElement->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