pyguymer3.elem2dict¶
- pyguymer3.elem2dict(elem, /, *, debug=True)[source]¶
Convert a XML element into a Python dictionary
This function accepts a XML element and recursively turns it in to a Python dictionary.
- Parameters:
elem (lxml.etree._Element) – the XML element
debug (bool, optional) – print debug messages
- Returns:
ans – the XML element as a Python dictionary
- Return type:
Notes
If present, non-empty text will be mapped to a “$$TEXT$$” dictionary field (it is assumed that the XML does not contain any tags called “$$TEXT$$” otherwise). If present, non-empty attributes will be mapped to “::KEY::” dictionary fields (it is assumed that the XML does not contain any tags called “::KEY::” otherwise). If present, child elements will be mapped to “KEY” dictionary fields. If multiple child elements have identical tag names then the “KEY” dictionary field will be a list of them.
Copyright 2017 Thomas Guymer [1]
References