Scans through the children of the node and makes a dictionary from the content.

Three cases are differentiated:

  1. If the node contains no other nodes, it is a text-node and {nodeName: text} is merged into the dictionary.

  2. If the node has the attribute method set to true, then it’s children will be appended to a list and this list is merged to the dictionary in the form: {nodeName:list}.

  3. Else, will call itself recursively on the nodes children (merging {nodeName: node_to_dict()} to the dictionary).


node (xml.etree.ElementTree.Element) – A XML element node.


dict – The XML element node as a dictionary.