Closed jlaura closed 3 years ago
Hi @jlaura,
Thanks for the question. This library uses cElementTree
to parse and write XML, specifically the tostring
function. It is called from the MetadataParser.serialize
method.
There isn't a built-in way to prettify metadata in this library, yet, but here's what you can do to get the results you want:
from xml.dom import minidom
class CustomFgdcParser(FgdcParser):
...
def serialize(self, use_template=False):
serialized = super(CustomFgdcParser, self).serialize(use_template)
return minidom.parseString(serialized).toprettyxml(indent=' '))
@dharvey-consbio Perfect! That is awesome. I'll go ahead and get the changes into my code. Many thanks!
How should one specify using newline characters when serializing xml metadata using custom parsers. For example, I am using the CustomFGDC parser that handles map projections. When I serialize an instance of that object, I am seeing the following:
I included extra output here to show the formatting on the projection fields (which are custom) and also the formatting on the contact fields (which are not custom). How is the code determining when to include a new line or not? Can this be contracted via this package or is this an issue in parseutils (I also did not see a means to be explicit in that library, but I only briefly skimmed the code base looking at the
write
methods.)Insight much appreciated!