

def element_to_string(element, encoding=None, xml_declaration=False):
    "\n    Returns a string from a XML object\n\n    Parameters\n    ----------\n    - element: etree Element\n    - encoding (optional): encoding in string form. 'utf-8', 'ISO-8859-1', etc.\n    - xml_declaration (optional): whether to include xml declaration\n\n    "
    output = None
    if (encoding is None):
        encoding = 'ISO-8859-1'
    if (etree.__name__ == 'lxml.etree'):
        if xml_declaration:
            if (encoding in ['unicode', 'utf-8']):
                output = ('<?xml version="1.0" encoding="utf-8" standalone="no"?>\n%s' % etree.tostring(element, encoding='unicode'))
            else:
                output = etree.tostring(element, encoding=encoding, xml_declaration=True)
        else:
            output = etree.tostring(element)
    elif xml_declaration:
        output = ('<?xml version="1.0" encoding="%s" standalone="no"?>\n%s' % (encoding, etree.tostring(element, encoding=encoding)))
    else:
        output = etree.tostring(element)
    return output

dataset/ETHPy150Open geopython/OWSLib/owslib/util.py element_to_string/original