I am parsing xml file with lxml python 3. converting the elements into dict of list of dict. But code is not working like it should and getting something weird, I tried with debugs and not able to figure out what is the issue:
Below is the snippet i wrote:
tree = lxml.etree.parse(self.meetingXmlFile)
root = tree.getroot()
roomList = []
for child in root.iter():
# print("Tag is ::%s and text is ::%s" % (child.tag , child.text))
if child.tag == "TowerName":
roomList.clear()
indexTower = child.text
# print(indexTower)
elif child.tag == "BigMeetingRooms" :
roomSize = "bigMeetingRoom"
elif child.tag == "SmallMeetingRooms":
roomSize = "smallMeetingRoom"
elif child.tag == "MeetingRoomName" :
roomName = child.text
elif child.tag == "MeetingRoomMailId" :
roomMailId = child.text
roomDict={roomName:roomMailId}
roomList.append(roomDict)
if roomSize == "bigMeetingRoom" :
# print(indexTower, " ", roomName, " ", roomMailId)
self.bigMeetingRoom[indexTower] = roomList
print(indexTower, " ", self.bigMeetingRoom[indexTower])
print(self.bigMeetingRoom)