"""Module containing some XML utility functions.
"""

from lxml import etree

###

RESULT_NS = {'R': 'http://www.infrae.com/namespaces/search'}

###

def parse_search_result ( xml ):
    doc = etree.fromstring(xml)
    nsdef = RESULT_NS
    ret = []
    rlist = doc.xpath('//R:resource', nsdef)
    # loop over all resources and create result dict
    for r in rlist:
        d = {}
        for e in ('url', 'size', 'mime-type', 'lastmodified'):
            d[e] = r.xpath('string(R:%s/text())' % e, nsdef)
        ret.append(d)
    # done
    return ret
#
##
