def xpath_id(svg, id):
    """ Convenience function for finding an xml element with a particular id """

    query = './/*[@id="' + id + '"]'
    targets = svg.xpath(query)
    if not targets:
        raise Exception("No elements found with id=%s" % id)
    if len(targets) > 1:
        raise Exception("Multiple elements found with id=%s" % id)
    return targets[0]