开发者

querying abstract elements in xpath with python

I'd like to make some xpath queries over abstract elements on the KML schema (like //AbstractFeatur开发者_如何学GoeType on a kml file).

I'm a noob in python and that make the research and trial quite painful, has anybody crossed the path of this beast during their developing hours?

Thanks,

Nico.


This is just an attempt using the page you provided. My code returns a list of elements who have tagtype==attrib. s is a string with your xml/kml.

import lxml.etree as etree
def find(s,attrib,tagtype='*'):
    tree = etree.fromstring(s)
    return tree.xpath(r'.//%s[@*="%s"]'%(tagtype,attrib))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜