2017-02-01 3 views
0
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와 같은 다른 for 루프를 사용하고 둘 다 추가하고 표시 할 수 있습니까?중첩 된 XML

+0

당신은 또한 우리에게 XML 파일을 보여 주시겠습니까 문제 해결해야 있나요? – Optimus

+0

다른 방법으로 빈 칸에 아무 것도 인쇄 할 수 없습니까? – Prasanna

+0

그것은 매우 거대한 .. – Prasanna

답변

0

itertools.izip_longest 기능을 살펴이이 빈 공간에 없음을 삽입하지 않습니다 및

rows=list(itertools.izip_longest(codeList,codeSystemList,codeSystemName,displayName,code,codeS,codeN,status,etime)) for row in rows: print(row)

+0

첫 번째 네 번째 열은 아무 것도 아닌 것처럼 보입니다. – Prasanna

+0

코드, 코드 ... 그들은 다시 codeList, codeSystemList 아래에 중첩됩니다. – Prasanna

+0

코드, 코드 ... 위의 xml 파일에 태그 아래의 하위 태그입니다. – Prasanna