Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XmlParser does not properly handle empty XML nodes #4

Closed
ClaasRostock opened this issue Sep 26, 2022 · 1 comment
Closed

XmlParser does not properly handle empty XML nodes #4

ClaasRostock opened this issue Sep 26, 2022 · 1 comment

Comments

@ClaasRostock
Copy link
Collaborator

XmlParser saves 'None' as value for an empty node (i.e. a node that has neither attributes nor sub-nodes).
It should, though, better save an empty dict as value.

Background:
None is not iterable. A dict, though, would still evaluate to False if empty but stays iterable.

With None, Python code such as the following will cause an exception:

if '_attributes' in my_parsed_xml_dict[node_key]:

because my_parsed_xml_dict[node_key] is None.

If my_parsed_xml_dict[node_key] would be an empty dict, i.e. {}, the above code would still evaluate to False, but not crash.

@ClaasRostock
Copy link
Collaborator Author

See parser.py -> XmlParser -> Line 1480

ClaasRostock pushed a commit that referenced this issue Sep 27, 2022
…empty node is now saved as an empty dict, i.e. {}, instead of None.

This change solves issue #4.

Problem was that None is not iterable, and code such as the following had caused an exception:
if '_attributes' in my_parsed_xml_dict[node_key]:
	...
because my_parsed_xml_dict[node_key] had been None.

Now, with this code change in place, my_parsed_xml_dict[node_key] would resolve not anylonger to None but to an empty dict ( {} ). As the dict is formally iterable (even when empty), above code does not crash.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant