# coding: utf-8 from lxml import etree as ET users = ET.Element('users') user = ET.SubElement(users, 'user') name = ET.SubElement(user, 'name') name.text = u'张三' age = ET.SubElement(user, 'age') age.text = u'25' age.attrib['bod'] = '1986.8' sex = ET.SubElement(user, 'sex') sex.text = u'男' print ET.tostring(users, pretty_print=True, xml_declaration=True, encoding='utf-8') # write to file: tree = ET.ElementTree(users) tree.write('users.xml', pretty_print=True, xml_declaration=True, encoding='utf-8')
效果如下(输出的XML是格式化的):
呵呵,谢谢
VaTG790i.最好的<a href=http://www.kyfei.com>网站推广软件</a>,
非常好
....................
;ui;普i;uighur;ui;ui;个
在unix网络编程中看到了关于TCP/IP的一些内容,我感觉还是写的不够。正在下载中,一定
下载地址呢