使用python生成xml的新手。请指导解决问题。
我正在尝试使用以下lng和python创建一个xml文件。
<StacksCollection>
<Stack ID="1" Name="flt_stack1" Size="1000000" Mode="E_CIRCULAR" OffBoardNotification="false" Counted="true" OffBoardNotifNoCtx="false" src="Editor" />
<Stack ID="2" Name="flt_stack2" Size="1000000" Mode="E_CIRCULAR" OffBoardNotification="false" Counted="true" OffBoardNotifNoCtx="false" src="Editor" />
<Stack ID="3" Name="flt_stack3" Size="1000000" Mode="E_CIRCULAR" OffBoardNotification="false" Counted="true" OffBoardNotifNoCtx="false" src="Editor" />
<Stack ID="4" Name="flt_stack4" Size="1000000" Mode="E_CIRCULAR" OffBoardNotification="false" Counted="true" OffBoardNotifNoCtx="false" src="Editor" />
</StacksCollection>
和我的代码如下
StacksCollection= ET.Element(Global_var_xmlWrite.Find_StackCollection)
for i in range(Global_var_xmlWrite.No_of_ID):
StacksCollection.append(ET.SubElement(StacksCollection,Global_var_xmlWrite.Stack,Global_var_xmlWrite.ID[i],Global_var_xmlWrite.Name[i],Global_var_xmlWrite.Size[i],Global_var_xmlWrite.Mode[i],Global_var_xmlWrite.OffBoardNotification[i],Global_var_xmlWrite.Counted[i],Global_var_xmlWrite.OffBoardNotifNoCtx[i],Global_var_xmlWrite.src[i]))
templateXml.write(tostring((StacksCollection),pretty_print=True, xml_declaration=False, encoding='UTF-8').decode('utf-8'))
出现如下错误
TypeError: SubElement() takes at most 4 positional arguments (10 given)
但是我无法减少争论,我该如何克服这个错误?