def test_convert_xlink_href(self, name_map, xml_input_filename, xml_expected_filename): xmlio.register_xmlns() root = xmlio.parse(sample_xml(xml_input_filename)) xlink_count = xmlio.convert_xlink_href(root, name_map) xml_output = xmlio.output(root) xml_output_expected = None with open(sample_xml(xml_expected_filename), "rb") as xml_file: xml_output_expected = xml_file.read() self.assertEqual(xml_output, xml_output_expected)
def rewrite_xml_file(self, xml_filename, file_name_map): local_xml_filename = path.join(self.get_tmp_dir(), xml_filename) xmlio.register_xmlns() root = xmlio.parse(local_xml_filename) # Convert xlink href values total = xmlio.convert_xlink_href(root, file_name_map) # Start the file output reparsed_string = xmlio.output(root) f = open(local_xml_filename, 'wb') f.write(reparsed_string) f.close()
def convert_xml(xml_file, file_name_map): # Register namespaces xmlio.register_xmlns() root, doctype_dict = xmlio.parse(xml_file, return_doctype_dict=True) # Convert xlink href values total = xmlio.convert_xlink_href(root, file_name_map) # TODO - compare whether all file names were converted # Start the file output reparsed_string = xmlio.output(root, type=None, doctype_dict=doctype_dict) f = open(xml_file, 'wb') f.write(reparsed_string) f.close()
def convert_xml(self, xml_file, file_name_map): # Register namespaces xmlio.register_xmlns() root, doctype_dict = xmlio.parse(xml_file, return_doctype_dict=True) # Convert xlink href values total = xmlio.convert_xlink_href(root, file_name_map) # TODO - compare whether all file names were converted # Start the file output reparsed_string = xmlio.output(root, type=None, doctype_dict=doctype_dict) f = open(xml_file, 'wb') f.write(reparsed_string) f.close()
def rewrite_xml_file(self, xml_filename, file_name_map): local_xml_filename = path.join(self.get_tmp_dir(), xml_filename) xmlio.register_xmlns() root, doctype_dict = xmlio.parse(local_xml_filename, return_doctype_dict=True) # Convert xlink href values total = xmlio.convert_xlink_href(root, file_name_map) # Start the file output reparsed_string = xmlio.output(root, type=None, doctype_dict=doctype_dict) f = open(local_xml_filename, 'wb') f.write(reparsed_string) f.close()