0
xml.ElementTree를 사용하여 파이썬 목록을 반복하고이를 트리 구조의 xml 파일에 씁니다. 다음 코드는 다음과 같습니다. any1 날 도와주세요!xml 요소 트리 : 예상 된 출력을 얻지 못했습니다.
import xml.etree.ElementTree as ET
sample = ['germany','India','USA','srilanka']
root = ET.Element("root")
data = ET.SubElement(root, "data")
title = ET.SubElement(data, "country")
for a in sample:
title.text = a
data.append('title')
tree = ET.ElementTree(root)
tree.write("page.xml")
- <root>
<data>
<country>srilanka</country>
<country>srilanka</country>
<country>srilanka</country>
<country>srilanka</country>
<country>srilanka</country>
</data>
</root>
Expected output
<root>
<data>
<country>germany</country>
<country>india</country>
<country>usa</country>
<country>srilanka</country>
</data>
</root>
내가 이런 식으로 출력을 필요로 전류 출력 ... 도와주세요! 미리 감사드립니다.
고마워요 !! # – Sangamesh