Selecting element by ID, in .svg xml

不问归期 提交于 2019-12-04 15:10:12

You're forgetting the SVG namespace, which is declared on the root element (xmlns="http://www.w3.org/2000/svg"). Hence, you want something like this:

SVG_NS = "http://www.w3.org/2000/svg"

def parse_xml():
    tree = ElementTree()
    tree.parse("torso-human.svg")                        
    for node in tree.findall('.//{%s}rect' % SVG_NS):
        print 'n=', node

See http://effbot.org/zone/element-namespaces.htm for some more details.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!