<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def parse_xml(self, xml_file, check_version=True, check_root=True, encoding=None):
 """Creates a python-stix STIXPackage object from the supplied xml_file. Args: xml_file: A filename/path or a file-like object representing a STIX instance document check_version: Inspect the version before parsing. check_root: Inspect the root element before parsing. encoding: The character encoding of the input `xml_file`. If ``None``, an attempt will be made to determine the input character encoding. Raises: .UnknownVersionError: If `check_version` is ``True`` and `xml_file` does not contain STIX version information. .UnsupportedVersionError: If `check_version` is ``False`` and `xml_file` contains an unsupported STIX version. .UnsupportedRootElement: If `check_root` is ``True`` and `xml_file` contains an invalid root element. """


        xml_etree = get_etree(xml_file, encoding=encoding)
        entity_obj = self.parse_xml_to_obj(
            xml_file=xml_etree,
            check_version=check_version,
            check_root=check_root
        )

        xml_root_node = xml_etree.getroot()
        entity = self.get_entity_class(xml_root_node.tag).from_obj(entity_obj)

        # Save the parsed nsmap and schemalocations onto the parsed Entity
        entity.__input_namespaces__ = dict(iteritems(xml_root_node.nsmap))
        with ignored(KeyError):
            pairs = get_schemaloc_pairs(xml_root_node)
            entity.__input_schemalocations__ = dict(pairs)

        return entity