def _element2dict(self, parent):
        """
        将单个节点转换为 dict
        """
        d = {}
        for node in parent.childNodes:
            if not isinstance(node, minidom.Element):
                continue
            if not node.hasChildNodes():
                continue

            if node.childNodes[0].nodeType == minidom.Node.ELEMENT_NODE:
                try:
                    d[node.tagName]
                except KeyError:
                    d[node.tagName] = []
                d[node.tagName].append(self._element2dict(node))
            elif len(node.childNodes) == 1 and node.childNodes[0].nodeType in [minidom.Node.CDATA_SECTION_NODE, minidom.Node.TEXT_NODE]:
                d[node.tagName] = node.childNodes[0].data
        return d
def _element2dict(self, parent):
        """
        将单个节点转换为 dict
        """
        d = {}
        for node in parent.childNodes:
            if not isinstance(node, minidom.Element):
                continue
            if not node.hasChildNodes():
                continue

            if node.childNodes[0].nodeType == minidom.Node.ELEMENT_NODE:
                try:
                    d[node.tagName]
                except KeyError:
                    d[node.tagName] = []
                d[node.tagName].append(self._element2dict(node))
            elif len(node.childNodes) == 1 and node.childNodes[0].nodeType in [minidom.Node.CDATA_SECTION_NODE, minidom.Node.TEXT_NODE]:
                d[node.tagName] = node.childNodes[0].data
        return d
def _element2dict ( self , parent ) : d = { } for node in parent . childNodes : if not isinstance ( node , minidom . Element ) : continue if not node . hasChildNodes ( ) : continue if node . childNodes [ 0 ] . nodeType == minidom . Node . ELEMENT_NODE : try : d [ node . tagName ] except KeyError : d [ node . tagName ] = [ ] d [ node . tagName ] . append ( self . _element2dict ( node ) ) elif len ( node . childNodes ) == 1 and node . childNodes [ 0 ] . nodeType in [ minidom . Node . CDATA_SECTION_NODE , minidom . Node . TEXT_NODE ] : d [ node . tagName ] = node . childNodes [ 0 ] . data return d
将单个节点转换为 dict
将单个节点转换为 dict