Python lxml parsing svg file

做~自己de王妃 提交于 2019-12-04 07:34:37

.parse() returns an ElementTree, which represents the tree as a whole. To query individual nodes, you need an Element, most likely the root element of the tree.

Replace part of your code with this:

xml = ET.parse('0f9ab.svg')
svg = xml.getroot()
print(svg)  # <lxml.etree._ElementTree object at 0x7f3a2f659ec8>

and I think you'll have some success.

Note also that .findall() requires a relative path and, in your case, a namespace qualifier:

print(svg.findall(".//{http://www.w3.org/2000/svg}g"))
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!