def dirToXML(self, directory):
    curdir = os.getcwd()
os.chdir(directory)
xmlOutput = ''
pathName = string.split(directory, os.sep)
xmlOutput += '<dir><name><![CDATA[' + pathName.pop() + ']]></name>'
for item in os.listdir(directory):
    if os.path.isfile(os.path.join(directory, item)):
        xmlOutput += '<file><name><![CDATA[' + item + ']]></name></file>'
else:
    xmlOutput += self.dirToXML(os.path.join(directory, item))
xmlOutput += '</dir>'
os.chdir(curdir)
return xmlOutput
os.walk() python: xml representation of a directory structure, recursion