Python 将一个标记及其xml文件内容写入另一个xml文件
我有一个巨大的xml文件,其中有许多标记。我需要提取一个标记的一个内容,并使用python代码将其写入另一个xml文件。 以下是xml代码示例:Python 将一个标记及其xml文件内容写入另一个xml文件,python,xml,Python,Xml,我有一个巨大的xml文件,其中有许多标记。我需要提取一个标记的一个内容,并使用python代码将其写入另一个xml文件。 以下是xml代码示例: <madamira_output xmlns="urn:edu.columbia.ccls.madamira.configuration:0.1"> <out_seg id="SENT1"> <word1>.....</word1> <word2
<madamira_output xmlns="urn:edu.columbia.ccls.madamira.configuration:0.1">
<out_seg id="SENT1">
<word1>.....</word1>
<word2>.....</word2>
</out_seg>
<out_seg id="SENT2">
<word1>.....</word1>
<word2>.....</word2>
</out_seg>
但文件中没有写入任何内容。请帮助out\u seg的子元素格式不正确。结束标记(word 1)与开始标记(word_1)不匹配 其次,使用以下代码将元素内容写入文件: 以open(completeName,“w”)作为f:
from xml.etree import ElementTree
with open('100.xml', 'rt') as f:
tree = ElementTree.parse(f)
sent=[]
for node in tree.iter('{urn:edu.columbia.ccls.madamira.configuration:0.1}out_seg'):
sent.append(node)
count_file=1
for i in sent:
save_path = '/Desktop/13/out'
completeName = os.path.join(save_path, str(count_file)+".xml")
count_file=count_file+1
with open(completeName, "w") as f:
f.write(i)
f.write(ElementTree.tostring(i))