■ XML을 생성하는 방법을 보여준다.
▶ 예제 코드 (PY)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
from xml.etree.ElementTree import Element, SubElement, dump noteElement = Element("note") noteElement.attrib["date"] = "20171219" SubElement(noteElement, "to" ).text = "Tove" SubElement(noteElement, "from" ).text = "Jani" SubElement(noteElement, "heading").text = "Reminder" SubElement(noteElement, "body" ).text = "Don't forget me this weekend!" dump(noteElement) """ <note date="20171219"><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note> """ |