■ Element 클래스의 iter 메소드를 사용해 자신을 포함해 모든 자식 XML 노드들을 순차 처리하는 방법을 보여준다.
▶ 예제 코드 (PY)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
from xml.etree.ElementTree import Element, SubElement 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!" for node in noteElement.iter(): print(node) """ <Element 'note' at 0x000001BF45682D40> <Element 'to' at 0x000001BF45682DE0> <Element 'from' at 0x000001BF45683F60> <Element 'heading' at 0x000001BF4569C900> <Element 'body' at 0x000001BF4569F420> """ |