目前尚不清楚您要执行的 *** 作,但是此代码会产生您想要的输出:
from lxml import etree as ETdef filter_by_itemid(doc, idlist): rowset = doc.xpath("/api/result/rowset[@name='assets']")[0] for elem in rowset.getchildren(): if int(elem.get("itemID")) not in idlist: rowset.remove(elem) return docdoc = ET.parse("test.xml")filter_by_itemid(doc, [1004072840841])print(ET.tostring(doc))
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)