【发布时间】:2011-10-14 09:44:09
【问题描述】:
我有一个 XML 文档,我想在其中搜索某些元素以及它们是否符合某些条件 我想删除它们
但是,我似乎无法访问该元素的父元素以便将其删除
file = open('test.xml', "r")
elem = ElementTree.parse(file)
namespace = "{http://somens}"
props = elem.findall('.//{0}prop'.format(namespace))
for prop in props:
type = prop.attrib.get('type', None)
if type == 'json':
value = json.loads(prop.attrib['value'])
if value['name'] == 'Page1.Button1':
#here I need to access the parent of prop
# in order to delete the prop
有什么办法可以做到吗?
谢谢
【问题讨论】:
标签: python elementtree