From 377a339263262379d13494ab406de892156b2754 Mon Sep 17 00:00:00 2001 From: Michael Witten Date: Thu, 24 Aug 2017 18:41:04 +0000 Subject: [PATCH] scour.py: minor rearrangement for clarity and efficiency --- scour/scour.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/scour/scour.py b/scour/scour.py index cd713d8..f8e2802 100644 --- a/scour/scour.py +++ b/scour/scour.py @@ -3216,14 +3216,15 @@ def serializeXML(element, options, ind=0, preserveWhitespace=False): outParts.extend([(I * ind), '<', element.nodeName]) # always serialize the id or xml:id attributes first - if element.getAttribute('id') != '': - id = element.getAttribute('id') + id = element.getAttribute('id') + if id != '': quot = '"' if id.find('"') != -1: quot = "'" outParts.extend([' id=', quot, id, quot]) - if element.getAttribute('xml:id') != '': - id = element.getAttribute('xml:id') + + id = element.getAttribute('xml:id') + if id != '': quot = '"' if id.find('"') != -1: quot = "'" @@ -3282,9 +3283,12 @@ def serializeXML(element, options, ind=0, preserveWhitespace=False): elif attrValue == 'default': preserveWhitespace = False - # if no children, self-close children = element.childNodes - if children.length > 0: + if children.length == 0: + outParts.append('/>') + if indent > 0: + outParts.append(newline) + else: outParts.append('>') onNewLine = False @@ -3319,10 +3323,6 @@ def serializeXML(element, options, ind=0, preserveWhitespace=False): outParts.extend(['']) if indent > 0: outParts.append(newline) - else: - outParts.append('/>') - if indent > 0: - outParts.append(newline) return "".join(outParts)