Index: src/OFXMLElement.m ================================================================== --- src/OFXMLElement.m +++ src/OFXMLElement.m @@ -466,11 +466,10 @@ OFString *prefix, *parentPrefix; OFXMLAttribute **attributesCArray; OFString *ret, *tmp; OFMutableDictionary *allNamespaces; OFString *defaultNS; - BOOL indentAfter = YES; if (characters != nil) return [characters stringByXMLEscaping]; if (CDATA != nil) @@ -607,34 +606,44 @@ if (children != nil) { OFXMLElement **childrenCArray = [children cArray]; size_t childrenCount = [children count]; IMP append; SEL appendSel = @selector(appendCStringWithoutUTF8Checking:); + BOOL indent; tmp = [OFMutableString string]; append = [tmp methodForSelector: appendSel]; + + if (indentation > 0) { + indent = YES; + + for (j = 0; j < childrenCount; j++) { + if (childrenCArray[j]->name == nil) { + indent = NO; + break; + } + } + } else + indent = NO; for (j = 0; j < childrenCount; j++) { - if (indentation > 0 && childrenCArray[j]->name != nil) + if (indent) append(tmp, appendSel, "\n"); append(tmp, appendSel, [[childrenCArray[j] _XMLStringWithParent: self - indentation: indentation + indentation: (indent ? indentation : 0) level: level + 1] cString]); } - if (indentation > 0 && childrenCount > 0 && - childrenCArray[j - 1]->name != nil) + if (indent) append(tmp, appendSel, "\n"); - else - indentAfter = NO; length += [tmp cStringLength] + [name cStringLength] + 2 + - (indentAfter ? level * indentation : 0); + (indent ? level * indentation : 0); @try { cString = [self resizeMemory: cString toSize: length]; } @catch (id e) { [self freeMemory: cString]; @@ -644,11 +653,11 @@ cString[i++] = '>'; memcpy(cString + i, [tmp cString], [tmp cStringLength]); i += [tmp cStringLength]; - if (indentAfter) + if (indent) for (j = 0; j < level * indentation; j++) cString[i++] = ' '; cString[i++] = '<'; cString[i++] = '/';