■ ElementTree 클래스의 getroot 메소드를 사용해 루트 엘리먼트를 구하는 방법을 보여준다.
▶ 예제 코드 (PY)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
from xml.etree.ElementTree import ElementTree, 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!" elementTree = ElementTree(noteElement) print(elementTree.getroot()) """ <Element 'note' at 0x0000024A9BD03E20> """ |