Closed bockor closed 4 years ago
Was just looking at this repo and saw this. Worth noting the stdlib has a xml pretty printer: https://docs.python.org/3/library/xml.dom.minidom.html#xml.dom.minidom.Node.toprettyxml
So a simple way to pretty print xml is:
xml_str = obj.to_xml()
xml_obj = xml.dom.minidom.parse(xml_str)
pretty = xml_object.toprettyxml()
Of course this is not the most efficient as you are serializing, parsing, serializing.
Thank you both.
I've just added support for optional pretty printing using the toprettyxml()
method provided by xml.dom.minidom
; I think it's preferable to use the standard library rather than snippets of code from StackOverflow.
The added indent_xml method in the Graph class provides pretty printed xml formatted .graphml files