@@ -994,10 +994,29 @@ namespace: (OFString*)elementNS { return [[self elementsForName: elementName namespace: elementNS] firstObject]; } + +- (OFArray*)elements +{ + OFMutableArray *ret = [OFMutableArray array]; + OFXMLElement **cArray = [children cArray]; + size_t i, count = [children count]; + + for (i = 0; i < count; i++) + if (cArray[i]->name != nil) + [ret addObject: cArray[i]]; + + /* + * Class swizzle the array to be immutable. We declared the return type + * to be OFArray*, so it can't be modified anyway. But not swizzling it + * would create a real copy each time -[copy] is called. + */ + ret->isa = [OFArray class]; + return ret; +} - (OFArray*)elementsForName: (OFString*)elementName { OFMutableArray *ret = [OFMutableArray array]; OFXMLElement **cArray = [children cArray]; @@ -1006,10 +1025,36 @@ for (i = 0; i < count; i++) if (cArray[i]->ns == nil && [cArray[i]->name isEqual: elementName]) [ret addObject: cArray[i]]; + /* + * Class swizzle the array to be immutable. We declared the return type + * to be OFArray*, so it can't be modified anyway. But not swizzling it + * would create a real copy each time -[copy] is called. + */ + ret->isa = [OFArray class]; + return ret; +} + +- (OFArray*)elementsForNamespace: (OFString*)elementNS +{ + OFMutableArray *ret = [OFMutableArray array]; + OFXMLElement **cArray = [children cArray]; + size_t i, count = [children count]; + + for (i = 0; i < count; i++) + if (cArray[i]->name != nil && + [cArray[i]->ns isEqual: elementNS]) + [ret addObject: cArray[i]]; + + /* + * Class swizzle the array to be immutable. We declared the return type + * to be OFArray*, so it can't be modified anyway. But not swizzling it + * would create a real copy each time -[copy] is called. + */ + ret->isa = [OFArray class]; return ret; } - (OFArray*)elementsForName: (OFString*)elementName namespace: (OFString*)elementNS @@ -1028,10 +1073,16 @@ for (i = 0; i < count; i++) if ([cArray[i]->ns isEqual: elementNS] && [cArray[i]->name isEqual: elementName]) [ret addObject: cArray[i]]; + /* + * Class swizzle the array to be immutable. We declared the return type + * to be OFArray*, so it can't be modified anyway. But not swizzling it + * would create a real copy each time -[copy] is called. + */ + ret->isa = [OFArray class]; return ret; } - (BOOL)isEqual: (id)object {