consbio / gis-metadata-parser

Parser for GIS metadata standards including ArcGIS, FGDC and ISO-19115
BSD 3-Clause "New" or "Revised" License
20 stars 3 forks source link

Error serializing FGDC example #4

Closed jlaura closed 3 years ago

jlaura commented 3 years ago

I am trying to serialize my own fgdc file and am seeing the following when attempting to serialize:

~/anaconda3/envs/amg/lib/python3.9/site-packages/parserutils/elements.py in element_is_empty(elem_to_parse, element_path)
    263         (element.tail is None or not element.tail.strip()) and
    264         (element.attrib is None or not len(element.attrib)) and
--> 265         (not len(element.getchildren()))
    266     )
    267 

AttributeError: 'xml.etree.ElementTree.Element' object has no attribute 'getchildren'

I have tracked this down to an issue in the data_map on the contacts key. I assumed that the issue was my metadata file (perhaps I missed a key?) so I went here and pulled an example rom fgdc.gov. I am seeing the same error attempting to serialize. GitHub is not supporting an xml upload though I can upload the file as plaintext.

Here is the code that I am using:

from gis_metadata.fgdc_metadata_parser import FgdcParser

with open('sample.xml', 'r') as metadata:
    data = FgdcParser(metadata)
    data.serialize()

Perhaps this is operator error or a lack of understanding about how to serialize the data?

As an aside, I have very much appreciated working with this library and using it to get programatic access to the metadata records. Thanks to the maintainers!

nikmolnar commented 3 years ago

@jlaura , thanks for reporting this issue! I'm guessing you're using Python 3.9 because it looks like the .getchildren() method has been deprecated for a while, and was finally removed in 3.9. I'll see about getting a fix for this (the main maintainer is off for a couple weeks, so it might wait until then), but in the meantime, it should work fine in Python 3.8 or older.

jlaura commented 3 years ago

@nikmolnar Sounds great! I would not have known to look for a deprecated XML method. I'm spoiled getting work a bunch on the JSON side of things usually. 😉

The workaround will work great so no rush here and many thanks for the info.

Edit: I downgraded my condo env to py=3.8 and this worked beautifully! Thanks again.

dharvey-consbio commented 3 years ago

This has been fixed in gis-metadata-parser version 1.2.5 by requiring parserutils version 1.2.3. For previous versions you can also just update parserutils this way: pip install parserutils --upgrade.