def _xml_to_json(element, stack, dictionary):
'''
This method creates a json representation of the given xml structure. It
traverses the dom tree and adds elements to the dictionary as it goes.
'''
stack.append(element.nodeName)
LOGGER.debug('Processing %s element.', element.nodeName)
if (
element.firstChild and
element.firstChild.nodeValue and
len(element.firstChild.nodeValue.strip())
):
put_in_dictionary(dictionary, stack, parse_value(element.firstChild.nodeValue.strip()))
else:
# This line might be removed.
put_in_dictionary(dictionary, stack, {})
for child in element.childNodes:
if child.nodeType == dom.Node.ELEMENT_NODE:
_xml_to_json(child, stack, dictionary)
stack.pop()
评论列表
文章目录