diff --git a/Classes/GPXExtensionsElement.swift b/Classes/GPXExtensionsElement.swift index 0c3fe81..bc33783 100644 --- a/Classes/GPXExtensionsElement.swift +++ b/Classes/GPXExtensionsElement.swift @@ -57,25 +57,24 @@ open class GPXExtensionsElement: GPXElement, Codable { override func addOpenTag(toGPX gpx: NSMutableString, indentationLevel: Int) { let attribute = NSMutableString() - for (key, value) in attributes { - attribute.appendFormat(" %@=\"%@\"", key, value) + if !attributes.isEmpty { + for (key, value) in attributes { + attribute.appendFormat(" %@=\"%@\"", key, value) + } + gpx.appendOpenTag(indentation: indent(forIndentationLevel: indentationLevel), tag: tagName(), attribute: attribute) + } + else if let text = text { + self.addProperty(forValue: text, gpx: gpx, tagName: tagName(), indentationLevel: indentationLevel) } - gpx.appendOpenTag(indentation: indent(forIndentationLevel: indentationLevel), tag: tagName(), attribute: attribute) } override func addChildTag(toGPX gpx: NSMutableString, indentationLevel: Int) { super.addChildTag(toGPX: gpx, indentationLevel: indentationLevel) - if let text = text { - self.addProperty(forValue: text, gpx: gpx, tagName: tagName(), indentationLevel: indentationLevel) - } + for child in children { - if let text = child.text { - self.addProperty(forValue: text, gpx: gpx, tagName: child.tagName(), indentationLevel: indentationLevel) - } - else { - child.gpx(gpx, indentationLevel: indentationLevel) - } + child.gpx(gpx, indentationLevel: indentationLevel) } } + }