내장된 Python xml 패키지에서 아직 지원되지 않기 때문에 현재 XML 문서에 네임스페이스를 직접 추가할 수 없습니다. 따라서 태그에 일반 속성으로 네임스페이스를 추가해야 합니다. 예를 들어,
import xml.dom.minidom
doc = xml.dom.minidom.Document()
element = doc.createElementNS('https://hello.world/ns', 'ex:el')
element.setAttribute("xmlns:ex", "https://hello.world/ns")
doc.appendChild(element)
print(doc.toprettyxml()) 이렇게 하면 문서가 제공됩니다.
<?xml version="1.0" ?> <ex:el xmlns:ex="https://example.net/ns"/>