cre-dev / xml2db

A Python package to load complex XML files into a relational database
https://cre-dev.github.io/xml2db/
MIT License
6 stars 3 forks source link

error parsing XSDs #13

Open nosovk opened 12 hours ago

nosovk commented 12 hours ago

I try to parse XSD from Brazilian goverment. https://www.gov.br/fazenda/pt-br/composicao/orgaos/secretaria-de-premios-e-apostas/arquivos/exemplos-de-arquivos-em-xsd.zip/@@download/file

for example JogosOnline_v1.00 1.xsd and got an error:

TypeError: object of type 'int' has no len()

It seems that <restriction base="int"> broken XSD schema parsing

the full trace:

Traceback (most recent call last):
  File "/mnt/c/Users/NosovK/WebstormProjects/cgt/reports-brasil/load.py", line 4, in <module>
    data_model = DataModel(
                 ^^^^^^^^^^
  File "/mnt/c/Users/NosovK/WebstormProjects/cgt/reports-brasil/xml2db_env/lib/python3.12/site-packages/xml2db/model.py", line 136, in __init__     
    self._build_model()
  File "/mnt/c/Users/NosovK/WebstormProjects/cgt/reports-brasil/xml2db_env/lib/python3.12/site-packages/xml2db/model.py", line 228, in _build_model 
    root_table = self._parse_tree(
                 ^^^^^^^^^^^^^^^^^
  File "/mnt/c/Users/NosovK/WebstormProjects/cgt/reports-brasil/xml2db_env/lib/python3.12/site-packages/xml2db/model.py", line 475, in _parse_tree  
    ) = recurse_parse_simple_type([ct])
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/c/Users/NosovK/WebstormProjects/cgt/reports-brasil/xml2db_env/lib/python3.12/site-packages/xml2db/model.py", line 388, in recurse_parse_simple_type
    mil = min([len(val) for val in elem_type.enumeration])
               ^^^^^^^^
TypeError: object of type 'int' has no len()
cre-os commented 8 hours ago

Yes you are correct, there is an issue there because it tries to get min and max length when we have an enumeration of string type, in order to get the max length for the column in the database. So it does not work with int enumerations. I'll try to do a quick fix; it should be quite easy. Thank you for pointing that out.