human
Complete this python program:
def check_optional(name, allowXHTML=False, merge_multiple=False):
assistant
#Here is the Python code you requested.

    """Validator for optional elements.
    @raise ManifestException: if validation fails
    """
    def check(n, filename):
        n = get_nodes_by_name(n, name)
        if ((len(n) > 1) and (not merge_multiple)):
            raise ManifestException(("Invalid    manifest    file:    must    have    a    single    '%s'    element" % name))
        if n:
            values = []
            for child in n:
                if allowXHTML:
                    values.append(''.join([x.toxml() for x in child.childNodes]))
                else:
                    values.append(_get_text(child.childNodes).strip())
            return ',    '.join(values)
    return check