这是我到目前为止所尝试过的。
from xml.etree.cElementTree import ElementTree
from xml.etree.cElementTree import Element
import os
def write_xml_file(self):
print os.path.isfile("/home/User_1/Project_Python/Scheduler.xml"),"The file exists ."
root = Element("backup ")
tree = ElementTree(root)
sub_element_1 = Element("first", item_status="1", cur_rec="")
root.append(sub_element_1)
sub_element_2 = Element("second", item_recno='2', bksetname=Scheduler.xml_dict['bksetname'], backup_start_time=Scheduler.xml_dict['backup_start_time'],
freq=Scheduler.xml_dict['freq'], email=Scheduler.xml_dict['email'])
root.append(sub_element_2)
tree.write(open("Scheduler.xml", "w+"))
Sceduler.xml文件输出:
<backup >
<first cur_rec="" item_status="1" />
<second backup_start_time="2015-12-08 17:00:09.112524" bksetname="Default_BackupSet_Admin" email="" freq="[1, 2, 3, 4, 5, 6, 7]" item_recno="2" />
</backup >
我希望只有一个标记作为我的Scheduler.xml文件的根目录,即我该怎么做?