jamesscottbrown / pyyed

A simple Python library to export networks to yEd
BSD 3-Clause "New" or "Revised" License
81 stars 37 forks source link

Update __init__.py #25

Closed bockor closed 4 years ago

bockor commented 4 years ago

The added indent_xml method in the Graph class provides pretty printed xml formatted .graphml files

cdonovick commented 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.

jamesscottbrown commented 4 years ago

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.