def getNamedElem(parent, nodename):
    """
    Return first subnode of given parent with given tag name, or None
    if there is no such subnode.
    """
    nodes = parent.getElementsByTagName(nodename)
    if nodes:
        return nodes[0]
    return None