[Python] XML Create and Write


파이썬에서 XML 을 작성하는 방법입니다.

<rss version="2.0">

<channel>

<item>

<title>subject</title>

<title>description</title>

</item>

</channel>

</rss>


위와 같은 XML 을 만드는 코드입니다.

import xml.etree.ElementTree as xml


rss = xml.Element('rss')

rss.set('version', '2.0')

ch = xml.SubElement(rss, 'channel')

it = xml.SubElement(ch, 'item')

ti = xml.SubElement(it, 'title')

de = xml.SubElement(it, 'title')

ti.text = str('subject')

de.text = str('description')

xml.dump(rss)

xml.ElementTree(rss).write('rss.xml')

이 외에도 만드는 방법이 더 있습니다.


블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,