■ ElementTree 클래스의 write 메소드를 사용해 XML 파일을 생성하는 방법을 보여준다.
▶ 예제 코드 (PY)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
import xml.etree.ElementTree noteElement = xml.etree.ElementTree.Element("note") noteElement.attrib["date"] = "20171219" xml.etree.ElementTree.SubElement(noteElement, "to" ).text = "Tove" xml.etree.ElementTree.SubElement(noteElement, "from" ).text = "Jani" xml.etree.ElementTree.SubElement(noteElement, "heading").text = "Reminder" xml.etree.ElementTree.SubElement(noteElement, "body" ).text = "Don't forget me this weekend!" xml.etree.ElementTree.ElementTree(noteElement).write("note.xml") |