我们如何在 python 中使用xml.dom(not lxml.etree) 删除 xml 代码中具有特定元素名称的标签。
例如,如果我们有以下 xml 代码:
<?xml version="1.0"?>
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications
with XML.</description>
</book>
<book id="bk102">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-12-16</publish_date>
<description>A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen
of the world.</description>
</book>
<book id="bk103">
<author>Corets, Eva</author>
<title>Maeve Ascendant</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-11-17</publish_date>
<description>After the collapse of a nanotechnology
society …Run Code Online (Sandbox Code Playgroud) 我有以下字符串:
s = '这是 sparta 1.2 版本。请检查。'
我想根据点分割它,同时忽略十进制数字。因此,所需的输出:
['这个','是sparta 1.2版本','请检查']
我尝试了以下操作:
re.split(r'\.(?!([\d+\.\d+]))',s)
Run Code Online (Sandbox Code Playgroud)
我得到的输出是:
['This ', None, 'is sparta 1.2 version', '', '请检查', None, '']
为什么我在这里得到 None 和空字符串?我只想要拆分字符串,即。
['这个','是sparta 1.2版本','请检查']
请在这里提出整改建议。