lxml を使用して XML 要素を削除しようとしていますが、メソッドは問題ないように見えますが、機能していません。それは私のコードです:
import lxml.etree as le
f = open('Bird.rdf','r')
doc=le.parse(f)
for elem in doc.xpath("//*[local-name() = 'dc' and namespace-uri() = 'http://purl.org/dc/terms/']"):
parent=elem.getparent().remove(elem)
print(le.tostring(doc))
サンプル XML ファイル:
<rdf:RDF xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:dc="http://purl.org/dc/terms/">
<wo:Class rdf:about="/nature/life/Bird#class">
<dc:description>Birds are a class of vertebrates. They are bipedal, warm-blooded, have a
covering of feathers, and their front limbs are modified into wings. Some birds, such as
penguins and ostriches, have lost the power of flight. All birds lay eggs. Because birds
are warm-blooded, their eggs have to be incubated to keep the embryos inside warm, or
they will perish</dc:description>
</wo:Class>
</rdf:RDF>