def _text_of_first_tag(dom, tag):
    """Returns the text inside the first tag of the dom object.

    Args:
        dom: The dom object.
        tag: The tag name.

    Returns:
        A string.

    Raises:
        ValueError: If dom object doesn't contain the specified tag or if the
          first tag doesn't have a text.
    """

    tags = dom.getElementsByTagName(tag)

    # Tag not found.
    if len(tags) == 0 or tags[0].firstChild is None:
        raise ValueError('No tag {} found'.format(tag))

    # No text in first tag.
    if tags[0].firstChild is None:
        raise ValueError('No text in tag {} found'.format(tag))

    return dom.getElementsByTagName(tag)[0].firstChild.nodeValue