2
저는 xml.dom.Element 객체를 가지고 있으며 XML을 포함하는 문자열로 변환하려고합니다. 이것에 대한 방법이없는 것 같습니까? 아니면 뭔가 빠져 있습니까?Pretty print Python xml.dom.Element 객체
저는 xml.dom.Element 객체를 가지고 있으며 XML을 포함하는 문자열로 변환하려고합니다. 이것에 대한 방법이없는 것 같습니까? 아니면 뭔가 빠져 있습니까?Pretty print Python xml.dom.Element 객체
사용 toprettyxml 또는 toxml 방법 : 예를 들어
elt.toprettyxml(indent = ' ')
,
import xml.dom.minidom as minidom
doc = minidom.Document()
foo = doc.createElement("foo")
doc.appendChild(foo)
print(foo.__class__)
# xml.dom.minidom.Element
print(foo.toprettyxml(indent = ' '))
# <foo/>