@@ -17,10 +17,11 @@ #include "config.h" #import "OFXMLAttribute.h" #import "OFString.h" #import "OFDictionary.h" +#import "OFXMLElement.h" #import "OFAutoreleasePool.h" @implementation OFXMLAttribute + attributeWithName: (OFString*)name namespace: (OFString*)ns @@ -71,36 +72,37 @@ - (OFString*)stringValue { return [[stringValue copy] autorelease]; } -- (OFString*)stringBySerializing -{ - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - OFMutableDictionary *dictionary = [OFMutableDictionary dictionary]; - OFString *ret; - - if (name != nil) - [dictionary setObject: name - forKey: @"name"]; - if (ns != nil) - [dictionary setObject: ns - forKey: @"namespace"]; - if (stringValue != nil) - [dictionary setObject: stringValue - forKey: @"stringValue"]; - - dictionary->isa = [OFDictionary class]; - - ret = [[OFString alloc] - initWithFormat: @"(class=OFXMLElement,version=0)<%@>", - [dictionary stringBySerializing]]; - - @try { - [pool release]; - } @finally { - [ret autorelease]; - } - - return ret; +- (OFXMLElement*)XMLElementBySerializing +{ + OFAutoreleasePool *pool; + OFXMLElement *element; + + element = [OFXMLElement elementWithName: @"object" + namespace: OF_SERIALIZATION_NS]; + + pool = [[OFAutoreleasePool alloc] init]; + + [element addAttributeWithName: @"class" + stringValue: [self className]]; + + [element addChild: + [OFXMLElement elementWithName: @"name" + namespace: OF_SERIALIZATION_NS + stringValue: name]]; + if (ns != nil) + [element addChild: + [OFXMLElement elementWithName: @"namespace" + namespace: OF_SERIALIZATION_NS + stringValue: ns]]; + [element addChild: + [OFXMLElement elementWithName: @"stringValue" + namespace: OF_SERIALIZATION_NS + stringValue: stringValue]]; + + [pool release]; + + return element; } @end