def parse(self, path_to_xml=None):
if not path_to_xml:<EOL><INDENT>if not self.path:<EOL><INDENT>self.logger.error("<STR_LIT>")<EOL>return<EOL><DEDENT>path_to_xml = self.path<EOL><DEDENT>root = self._clean_xml(path_to_xml)<EOL>if root.tag.lower() == '<STR_LIT>':<EOL><INDENT>tree = ET.ElementTree(root)<EOL>self.records = element_tree_collection_to_records(tree)<EOL><DEDENT>elif root.tag.lower() == '<STR_LIT>':<EOL><INDENT>new_root = ET.Element('<STR_LIT>')<EOL>new_root.append(root)<EOL>tree = ET.ElementTree(new_root)<EOL>self.records = element_tree_collection_to_records(tree)<EOL><DEDENT>else:<EOL><INDENT>header_subs = get_request_subfields(root)<EOL>records = root.find('<STR_LIT>')<EOL>if records is None:<EOL><INDENT>records = root.find('<STR_LIT>')<EOL><DEDENT>if records is None:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>tree = ET.ElementTree(records)<EOL>for record, is_deleted in element_tree_oai_records(tree, header_subs):<EOL><INDENT>if is_deleted:<EOL><INDENT>self.deleted_records.append(<EOL>self.create_deleted_record(record)<EOL>)<EOL><DEDENT>else:<EOL><INDENT>self.records.append(record)<EOL><DEDENT><DEDENT><DEDENT>
Parse an XML document and clean any namespaces.