I am attempting to parse an xml file which I have accomplished and pass the results into an array which will be used later on. The xml is opened read and parsed where I am picking out 3 elements (channel, start and title). As shown in code below, the start is date and time. I am able to split date and time and store in date. As the code loops thru each xml entry I would like to pick out the channel, start and title and store to a multidimensional array. I have done this in Brightscript but can't understand the array or list structure of Python. Once I have all entries in the array or list, I will need to parse that array pulling out all titles and dates with the same date. Can somebody guide me thru this?
xmldoc=minidom.parse (xmldoc)
programmes= xmldoc.getElementsByTagName("programme")
def getNodeText(node):
nodelist = node.childNodes
result = []
for node in nodelist:
if node.nodeType == node.TEXT_NODE:
result.append(node.data)
return ''.join(result)
title = xmldoc.getElementsByTagName("title")[0]
#print("Node Name : %s" % title.nodeName)
#print("Node Value : %s \n" % getNodeText(title))
programmes = xmldoc.getElementsByTagName("programme")
for programme in programmes:
cid = programme.getAttribute("channel")
starts=programme.getAttribute("start")
cutdate=starts[0:15]
year= int(cutdate[0:4])
month= int(cutdate[5:6])
day= int(cutdate[7:8])
hour= int(cutdate[9:10])
minute= int(cutdate[11:12])
sec= int(cutdate[13:14])
date=datetime(year, month, day,hour, minute, sec)
title = programme.getElementsByTagName("title")[0]
print("id:%s, title:%s, starts:%s" %
(cid, getNodeText(title), starts))
print (date)