'Saves the given element to the specified file.
The element to save is specified with ``source`` using the same
semantics as with `Get Element` keyword.
The file where the element is saved is denoted with ``path`` and the
encoding to use with ``encoding``. The resulting file always contains
the XML declaration.
The resulting XML file may not be exactly the same as the original:
- Comments and processing instructions are always stripped.
- Possible doctype and namespace prefixes are only preserved when
`using lxml`.
- Other small differences are possible depending on the ElementTree
or lxml version.
Use `Element To String` if you just need a string representation of
the element.'

def save_xml(self, source, path, encoding='UTF-8'):

    path = os.path.abspath(path.replace('/', os.sep))
    elem = self.get_element(source)
    tree = self.etree.ElementTree(elem)
    config = {'encoding': encoding}
    if self.modern_etree:
        config['xml_declaration'] = True
    if self.lxml_etree:
        elem = self._ns_stripper.unstrip(elem)
        if tree.docinfo.doctype:
            config['doctype'] = tree.docinfo.doctype
        tree = self.etree.ElementTree(elem)
    with open(path, 'wb') as output:
        if ('doctype' in config):
            output.write(self.etree.tostring(tree, **config))
        else:
            tree.write(output, **config)
    logger.info(('XML    saved    to    <a    href="file://%s">%s</a>.' % (path, path)), html=True)
