import xml.etree.ElementTree as ET
tree = ET.parse("D:\Parsed_CCD.xml")
doc = tree.getroot()
codeList=[]
codeSystemList=[]
codeSystemName=[]
displayName=[]
code=[]
codeS=[]
codeN=[]
display=[]
status=[]
stime=[]
etime=[]
for elem1 in doc.findall('.//medicationsInfo/entryInfo/productCode/code'):
codeList.append(elem1.text)
for elem2 in doc.findall('.//medicationsInfo/entryInfo/productCode/codeSystem'):
codeSystemList.append(elem2.text)
for elem3 in doc.findall('.//medicationsInfo/entryInfo/productCode/codeSystemName'):
codeSystemName.append(elem3.text)
for elem4 in doc.findall('.//medicationsInfo/entryInfo/productCode/displayName'):
displayName.append(elem4.text)
for elem5 in doc.findall('.//medicationsInfo/entryInfo/productCode/translation/code'):
code.append(elem5.text)
for elem6 in doc.findall('.//medicationsInfo/entryInfo/productCode/translation/codeSystem'):
codeS.append(elem6.text)
for elem7 in doc.findall('.//medicationsInfo/entryInfo/productCode/translation/codeSystemName'):
codeN.append(elem7.text)
for elem9 in doc.findall('.//medicationsInfo/entryInfo/productCode/translation/displayName'):
display.append(elem9.text)
for elem8 in doc.findall('.//medicationsInfo/entryInfo/statusCode'):
status.append(elem8.text)
for elem10 in doc.findall('.//medicationsInfo/entryInfo/startTime'):
stime.append(elem10.text)
for elem11 in doc.findall('.//medicationsInfo/entryInfo/endTime'):
etime.append(elem11.text)
for i in range(len(codeList)):
print (codeList[i],codeSystemList[i],codeSystemName[i],displayName[i],code[i],codeS[i],codeN[i],status[i],etime[i])
獲取所有數據,我需要打印的所有值列明智的,但問題是我在打印數據列明智的,但我不能,因爲我有一個獲取所有數據嵌套的xml文件,它具有不同數量的值。 for循環僅達到最小值,其餘數據不顯示。是否有可能像i和j一樣使用不同的循環,並將它們追加並顯示出來?無法從嵌套的XML
能否請您告訴我們還是XML文件? – Optimus
其他如何在空白處不打印任何東西? – Prasanna
這是非常巨大的.. – Prasanna