scour.py: minor rearrangement for clarity and efficiency

This commit is contained in:
Michael Witten 2017-08-24 18:41:04 +00:00
parent da770cefc3
commit 377a339263

View file

@ -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(['</', element.nodeName, '>'])
if indent > 0:
outParts.append(newline)
else:
outParts.append('/>')
if indent > 0:
outParts.append(newline)
return "".join(outParts)