Спасибо за отзывчивость)
Вот пример моего conf-файла:
[user1]
type = peer
username = Vasiliy
secret = CegthGfhjkm
disallow = all
allow = alaw,gsm
[user2]
type = peer
secret = wRu8jb0
username = Ivan
disallow = all
allow = alaw,gsm
А вот что у меня получилось за выходные:
import xml.etree.cElementTree as ET
import configparser
config = configparser.ConfigParser()
config.read('sipusers.conf')
dictionary = {}
for section in config.sections():
dictionary[section] = {}
for option in config.options(section):
dictionary[section][option] = config.get(section, option)
Main = ET.Element("Main")
ET.SubElement(Main, "TCMIPPhoneDirectory clearlight=\"true\"")
ET.SubElement(Main, "Title").text = "Phonelist"
ET.SubElement(Main, "Prompt").text = "Prompt"
for section in config.sections():
Child = ET.SubElement(Main, "DirectoryEntry")
ET.SubElement(Child, "Name").text = section
ET.SubElement(Child, "Telephone").text = dictionary[section]['username']
xml = ET.ElementTree(Main)
xml.write("phonebook.xml")
Прошу строго не судить, т.к. это мой первый опыт в программировании. Суть моей задачи в том, чтобы генерировать телефонную книгу для IP-телефонов. Вот как бы еще UTF-8 прикрутить, чтобы в xml русские буковки вставали?