tools (xml_tools): fix pFmtElt:

default URI was not handled correctly, and attributes were missing, this patch fixes
those bugs.
This commit is contained in:
Goffi 2021-02-19 15:53:25 +01:00
commit 843928bf02

View file

@ -1818,22 +1818,22 @@ def findAll(elt, namespaces=None, names=None):
yield found
def pFmtElt(elt, indent=0):
def pFmtElt(elt, indent=0, defaultUri=""):
"""Pretty format a domish.Element"""
strings = []
for child in elt.children:
if domish.IElement.providedBy(child):
strings.append(pFmtElt(child, indent+2))
strings.append(pFmtElt(child, indent+2, defaultUri=elt.defaultUri))
else:
strings.append(f"{(indent+2)*' '}{child!s}")
if elt.children:
nochild_elt = domish.Element(
(elt.uri, elt.name), elt.defaultUri, elt.attribs, elt.localPrefixes
(elt.uri, elt.name), elt.defaultUri, elt.attributes, elt.localPrefixes
)
strings.insert(0, f"{indent*' '}{nochild_elt.toXml()[:-2]}>")
strings.insert(0, f"{indent*' '}{nochild_elt.toXml(defaultUri=defaultUri)[:-2]}>")
strings.append(f"{indent*' '}</{nochild_elt.name}>")
else:
strings.append(f"{indent*' '}{elt.toXml()}")
strings.append(f"{indent*' '}{elt.toXml(defaultUri=defaultUri)}")
return '\n'.join(strings)