【问题标题】:join xml element.text in python在python中加入xml element.text
【发布时间】:2013-09-04 21:05:18
【问题描述】:

python 中是否有一些函数可以将 element.text 与相同的 Element.tag 名称连接起来?

例子:

 p>     
        some text
        <i>(</i>
        <i>something</i>
        <i>something</i>
        <i>)</i>
        some text
        <i>proň, zač</i>
        the end of paragraph
    </p>

我想要什么:

 p>     
        some text
        <i>(something something)</i>
        some text
        <i>proň, zač</i>
        the end of paragraph
    </p>

【问题讨论】:

    标签: python xml python-3.x xml.etree


    【解决方案1】:

    python中是否有一些函数可以将element.text与相同的标签名称连接起来?

    不,您必须自己编写代码。原因是该库处理 xml,而不仅仅是 xhtml。一般来说,&lt;tag&gt;a&lt;/tag&gt;&lt;tag&gt;b&lt;/tag&gt;&lt;tag&gt;ab&lt;/tag&gt; 的含义不同。事实上,即使在 html 中,合并相邻的 &lt;p&gt;&lt;block&gt; 标签也会改变文本的含义。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-04-06
      • 2020-06-06
      • 1970-01-01
      • 2012-04-19
      • 2021-03-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多