scour.py: minor rearrangement for clarity and efficiency
This commit is contained in:
parent
da770cefc3
commit
377a339263
1 changed files with 10 additions and 10 deletions
|
|
@ -3216,14 +3216,15 @@ def serializeXML(element, options, ind=0, preserveWhitespace=False):
|
||||||
outParts.extend([(I * ind), '<', element.nodeName])
|
outParts.extend([(I * ind), '<', element.nodeName])
|
||||||
|
|
||||||
# always serialize the id or xml:id attributes first
|
# always serialize the id or xml:id attributes first
|
||||||
if element.getAttribute('id') != '':
|
id = element.getAttribute('id')
|
||||||
id = element.getAttribute('id')
|
if id != '':
|
||||||
quot = '"'
|
quot = '"'
|
||||||
if id.find('"') != -1:
|
if id.find('"') != -1:
|
||||||
quot = "'"
|
quot = "'"
|
||||||
outParts.extend([' id=', quot, id, 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 = '"'
|
quot = '"'
|
||||||
if id.find('"') != -1:
|
if id.find('"') != -1:
|
||||||
quot = "'"
|
quot = "'"
|
||||||
|
|
@ -3282,9 +3283,12 @@ def serializeXML(element, options, ind=0, preserveWhitespace=False):
|
||||||
elif attrValue == 'default':
|
elif attrValue == 'default':
|
||||||
preserveWhitespace = False
|
preserveWhitespace = False
|
||||||
|
|
||||||
# if no children, self-close
|
|
||||||
children = element.childNodes
|
children = element.childNodes
|
||||||
if children.length > 0:
|
if children.length == 0:
|
||||||
|
outParts.append('/>')
|
||||||
|
if indent > 0:
|
||||||
|
outParts.append(newline)
|
||||||
|
else:
|
||||||
outParts.append('>')
|
outParts.append('>')
|
||||||
|
|
||||||
onNewLine = False
|
onNewLine = False
|
||||||
|
|
@ -3319,10 +3323,6 @@ def serializeXML(element, options, ind=0, preserveWhitespace=False):
|
||||||
outParts.extend(['</', element.nodeName, '>'])
|
outParts.extend(['</', element.nodeName, '>'])
|
||||||
if indent > 0:
|
if indent > 0:
|
||||||
outParts.append(newline)
|
outParts.append(newline)
|
||||||
else:
|
|
||||||
outParts.append('/>')
|
|
||||||
if indent > 0:
|
|
||||||
outParts.append(newline)
|
|
||||||
|
|
||||||
return "".join(outParts)
|
return "".join(outParts)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue