Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将一个标记及其xml文件内容写入另一个xml文件_Python_Xml - Fatal编程技术网

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

我有一个巨大的xml文件,其中有许多标记。我需要提取一个标记的一个内容,并使用python代码将其写入另一个xml文件。 以下是xml代码示例:

<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))