Index: src/OFXMLElement.m ================================================================== --- src/OFXMLElement.m +++ src/OFXMLElement.m @@ -316,10 +316,18 @@ attributes = [[attributesElement objectByDeserializing] copy]; namespaces = [[namespacesElement objectByDeserializing] copy]; children = [[childrenElement objectByDeserializing] copy]; + if (namespaces == nil) + namespaces = [[OFMutableDictionary alloc] init]; + + [namespaces setObject: @"xml" + forKey: @"http://www.w3.org/XML/1998/namespace"]; + [namespaces setObject: @"xmlns" + forKey: @"http://www.w3.org/2000/xmlns/"]; + if (name == nil) @throw [OFInvalidArgumentException exceptionWithClass: isa selector: _cmd]; @@ -712,17 +720,26 @@ [element addChild: attributesElement]; } if (namespaces != nil) { OFXMLElement *namespacesElement; + OFMutableDictionary *namespacesCopy = + [[namespaces mutableCopy] autorelease]; - namespacesElement = - [OFXMLElement elementWithName: @"namespaces" - namespace: OF_SERIALIZATION_NS]; - [namespacesElement addChild: - [namespaces XMLElementBySerializing]]; - [element addChild: namespacesElement]; + [namespacesCopy removeObjectForKey: + @"http://www.w3.org/XML/1998/namespace"]; + [namespacesCopy removeObjectForKey: + @"http://www.w3.org/2000/xmlns/"]; + + if ([namespacesCopy count] > 0) { + namespacesElement = + [OFXMLElement elementWithName: @"namespaces" + namespace: OF_SERIALIZATION_NS]; + [namespacesElement addChild: + [namespacesCopy XMLElementBySerializing]]; + [element addChild: namespacesElement]; + } } if (children != nil) { OFXMLElement *childrenElement; Index: tests/serialization.xml ================================================================== --- tests/serialization.xml +++ tests/serialization.xml @@ -31,46 +31,13 @@ Hello Wo ld! How are you? https://webkeks.org/ - - - - http://www.w3.org/2000/xmlns/ - - - xmlns - - - http://www.w3.org/XML/1998/namespace - - - xml - - - - - - - - http://www.w3.org/2000/xmlns/ - - - xmlns - - - http://www.w3.org/XML/1998/namespace - - - xml - - - - +