Q:

python lxml get the name of a node

This is my xml file:
<FuzzyComparison>
    <Modules>
        <Module>
            <name>AutosoukModelMakeFuzzyComparisonModule</name>
            <configurationLoader>DefaultLoader</configurationLoader>
            <configurationFile>MakesModels.conf</configurationFile>
            <settings></settings>
        </Module>
        <Module>
            <name>DefaultFuzzyComparisonModule</name>
            <configurationLoader>DefaultLoader</configurationLoader>
            <configurationFile>Buildings.conf</configurationFile>
            <settings>
                <attribute>building</attribute>
            </settings>
        </Module>
    </Modules>
    </FuzzyComparison>

This is the code I've been trying to parse it with:
from lxml import etree
class AttributesXMLParser():
    def __init__(self):
        self.doc=etree.parse('Items.xml')

    def getValueOfTag(self, tagName): #This function returns the value of a specific tag for exmaple, the tageName could be "FirstDate"
        return self.doc.find(tagName).text

    def loadFuzzySettings(self):
        modulesDict = list()
        modules = self.doc.findall('FuzzyComparison/Modules/Module')
        for module in modules:
            moduleDict = dict()
            moduleName = module.find('name').text
            moduleDict['name'] = moduleName
            moduleConfigurationLoader = module.find('configurationLoader').text
            moduleDict['configurationLoader'] = moduleConfigurationLoader
            moduleConfigurationFile = module.find('configurationFile').text
            moduleDict['moduleConfigurationFile'] = moduleConfigurationFile
            settings = module.findall('settings')
            settingsDict = dict()
            for oneSetting in settings:
                settingsDict[oneSetting] = oneSetting.text
            moduleDict['settings'] = settingsDict
            modulesDict.append(moduleDict)
        return modulesDict

and this is the results:
[{'moduleConfigurationFile': 'MakesModels.conf', 'configurationLoader': 'Default
Loader', 'name': 'AutosoukModelMakeFuzzyComparisonModule', 'settings': {<Element
 settings at 0x25257c8>: None}}, {'moduleConfigurationFile': 'Buildings.conf', '
configurationLoader': 'DefaultLoader', 'name': 'DefaultFuzzyComparisonModule', '
settings': {<Element settings at 0x2525e48>: '\n\t\t\t\t'}}]

My problem
I don't know how to get the name and value of the settings node, because as you see everything is working great except the settings, I need to have it like this:
"attribute": building

But my code gives me: 
{<Element settings at 0x2525e48>: '\n\t\t\t\t'}}]

Could you help please to solve that?

A:

Since findall() returns a list, you want to iterate over the contents of elements of that list, rather than the list itself.  You also want to use the element's tag as a key, rather than using the element itself.
settingsDict = {}
for settingsNode in module.findall('settings'):
    for setting in settingsNode:
        settingsDict[setting.tag] = setting.text

Or, if you only have one settings tag,
settingsDict = {}
for setting in module.find('settings'):
    settingsDict[setting.tag] = setting.text

Which can be simplified to:
settingsDict = {setting.tag: setting.text
                for setting in module.find('settings')}

