Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/277.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 如何清除etree中的节点以在同一节点位置为不同元素多次添加不同的文本_Python_Lxml_Lxml.objectify - Fatal编程技术网

Python 如何清除etree中的节点以在同一节点位置为不同元素多次添加不同的文本

Python 如何清除etree中的节点以在同一节点位置为不同元素多次添加不同的文本,python,lxml,lxml.objectify,Python,Lxml,Lxml.objectify,我正在尝试基于xml模板生成xml文档。xml模板包括一个表 这是我的模板 <title main=""></title> <body> <table> <title table=""></title> <tgroup cols="5" colsep="1"

我正在尝试基于xml模板生成xml文档。xml模板包括一个表

这是我的模板

    <title main=""></title>
      <body>
        <table>
            <title table=""></title>
            <tgroup cols="5" colsep="1" rowsep="1" align="left">
              <colspec colnum="c1" colname="1" colwidth="15*"/>
              <colspec colnum="c2" colname="2" colwidth="20*"/>
              <colspec colnum="c3" colname="3" colwidth="20*"/>
              <colspec colnum="c4" colname="4" colwidth="25*"/>
              <colspec colnum="c5" colname="5" colwidth="25"/>
              <tbody>
                <row rowsep="1" rowParamIn="">
                  <entry colname="1"><b>Parameters (in):</b></entry>
                  <entry colname="2" paramIn=""></entry>
                  <entry  paramInDes=""></entry>
                </row>
                <row rowsep="1" rowParamOut="">
                  <entry colname="1"><b>Parameters (out):</b></entry>
                  <entry colname="2" paramOut=""></entry>
                  <entry namest="3" nameend="5" paramOutDes=""></entry>
                </row>
                <row rowsep="1" rowParamInOut="">
                  <entry colname="1"><b>Parameters (in-out):</b></entry>
                  <entry colname="2" paramInOut=""></entry>
                  <entry namest="3" nameend="5" paramInOutDes=""></entry>
                </row>
                <row rowsep="1">
                  <entry colname="1"><b>Return:</b></entry>
                  <entry colname="2" return=""></entry>
                  <entry namest="3" nameend="5" returnDes=""></entry>
                </row>
              </tbody>
            </tgroup>
        </table>
      </body>
</topic>
此代码仅适用于第一个元素,但当循环扩展后,第二个第三个元素的文本…etc被追加,来自前一个元素的文本仍然嵌入到下一个元素的节点中

我想去掉上一个元素中的文本

主要思想是:与特定元素关联的文本将仅与该元素一起出现。它不必出现在其他元素中

谢谢 请帮忙

                    for item in Elements: 
                        entryIn = tObj.root.find(".//entry[@paramIn]")
                        entryInDes = tObj.root.find(".//entry[@paramInDes]")
                        entryOut = tObj.root.find(".//entry[@paramOut]")
                        entryOutDes = tObj.root.find(".//entry[@paramOutDes]")
                        entryInOut = tObj.root.find(".//entry[@paramInOut]")
                        entryInOutDes = tObj.root.find(".//entry[@paramInOutDes]")
                        
                        if ele.Type== "in":
                            
                            eleIn= E.p(f"{ele.Name}", colname="2")              # using lxml.objectify
                            paramInDes = E.p(f"{ele.Description}", namest="3", nameend="5")
                            entryIn.append(paramIn)
                            entryInDes.append(paramInDes)
                            
                        if ele.Direction == "out":
                            eleOut = E.p(f"{ele.Name}", colname="2")
                            eleOutDes = E.p(f"{ele.Description}", namest="3", nameend="5")
                            entryOut.append(eleOut)
                            entryOutDes.append(eleOutDes)