Beautify XML

    Args:
        src: xml string or path-to-file with text to beautify (mandatory)
        dest: path-to-file to save beautified xml string; if file doesn't exist
              it is created automatically; (optional)
              if this arg is skept function returns string
        shift: can be either integer or string
                1) if int - number of spaces in tab, for example shift=8
                <a>
                        <b></b>
                </a>
               2) if string - pattern, for example shift='....'
                <a>
                ....<b></b>
                </a>

    Returns: 1) beautified XML string if dest is not provided
             2) length of saved file if dest is provided

    Example:
            xml('path/to/file.xml')
            xml('path/to/file.xml', 'path/to/save/result.xml')
            xml('path/to/file.xml', 8)
            xml('path/to/file.xml', '____')
            xml('path/to/file.xml', 'path/to/save/result.xml', 2)

def xml(src, dest=False, shift=4):
    """Beautify XML

    Args:
        src: xml string or path-to-file with text to beautify (mandatory)
        dest: path-to-file to save beautified xml string; if file doesn't exist
              it is created automatically; (optional)
              if this arg is skept function returns string
        shift: can be either integer or string
                1) if int - number of spaces in tab, for example shift=8
                <a>
                        <b></b>
                </a>
               2) if string - pattern, for example shift='....'
                <a>
                ....<b></b>
                </a>

    Returns: 1) beautified XML string if dest is not provided
             2) length of saved file if dest is provided

    Example:
            xml('path/to/file.xml')
            xml('path/to/file.xml', 'path/to/save/result.xml')
            xml('path/to/file.xml', 8)
            xml('path/to/file.xml', '____')
            xml('path/to/file.xml', 'path/to/save/result.xml', 2)
    """
    if not dest:
        return _xml(_text(src)) # returns string
    else:
        if type(dest) is int:  # dest is skept, custom pattern provided at dist place
            return _xml(_text(src), dest)
        else:
            with open(dest, 'w') as f2:
                return f2.write(_xml(_text(src), shift))