@@ -20,10 +20,11 @@ #import "OFDictionary.h" #import "OFEnumerator.h" #import "OFArray.h" #import "OFString.h" +#import "OFXMLElement.h" #import "OFAutoreleasePool.h" #import "OFEnumerationMutationException.h" #import "OFInvalidArgumentException.h" #import "OFOutOfRangeException.h" @@ -755,61 +756,55 @@ */ ret->isa = [OFString class]; return ret; } -- (OFString*)stringBySerializing +- (OFXMLElement*)XMLElementBySerializing { - OFMutableString *ret; OFAutoreleasePool *pool, *pool2; + OFXMLElement *element; OFEnumerator *keyEnumerator, *objectEnumerator; - id key, object; - size_t i; - - if (count == 0) { - if ([self isKindOfClass: [OFMutableDictionary class]]) - return @"(mutable,0){}"; - else - return @"(0){}"; - } - - if ([self isKindOfClass: [OFMutableDictionary class]]) - ret = [OFMutableString stringWithFormat: @"(mutable,%zd){\n", - count]; - else - ret = [OFMutableString stringWithFormat: @"(%zd){\n", count]; + id key, object; + + element = [OFXMLElement elementWithName: @"object" + namespace: OF_SERIALIZATION_NS]; + pool = [[OFAutoreleasePool alloc] init]; + [element addAttributeWithName: @"class" + stringValue: [self className]]; + keyEnumerator = [self keyEnumerator]; objectEnumerator = [self objectEnumerator]; - i = 0; pool2 = [[OFAutoreleasePool alloc] init]; - while ((key = [keyEnumerator nextObject]) != nil && - (object = [objectEnumerator nextObject]) != nil) { - [ret appendString: [key stringBySerializing]]; - [ret appendString: @" = "]; - [ret appendString: [object stringBySerializing]]; + (object = [objectEnumerator nextObject]) != nil) { + OFXMLElement *pair, *keyElement, *valueElement; + + pair = [OFXMLElement elementWithName: @"pair" + namespace: OF_SERIALIZATION_NS]; + + keyElement = [OFXMLElement + elementWithName: @"key" + namespace: OF_SERIALIZATION_NS]; + [keyElement addChild: [key XMLElementBySerializing]]; + [pair addChild: keyElement]; + + valueElement = [OFXMLElement + elementWithName: @"value" + namespace: OF_SERIALIZATION_NS]; + [valueElement addChild: [object XMLElementBySerializing]]; + [pair addChild: valueElement]; - if (++i < count) - [ret appendString: @",\n"]; + [element addChild: pair]; [pool2 releaseObjects]; } - [ret replaceOccurrencesOfString: @"\n" - withString: @"\n\t"]; - [ret appendString: @"\n}"]; [pool release]; - /* - * Class swizzle the string to be immutable. We declared the return type - * to be OFString*, so it can't be modified anyway. But not swizzling it - * would create a real copy each time -[copy] is called. - */ - ret->isa = [OFString class]; - return ret; + return element; } @end @implementation OFDictionaryEnumerator - initWithDictionary: (OFDictionary*)dictionary_