def process_xml2csv(self, src_path, path_to_csv, header_values=None, empty_rows=1, encoding=ENCODING): if self.find_file(src_path): xml2csv(src_path, path_to_csv, header_values, empty_rows, encoding)
def to_csv(self): """Export table from xml engine to CSV file.""" for keys in list(self.script.tables): table_name = self.table_name() header = self.script.tables[keys].get_insert_columns(join=False, create=True) csv_outfile = xml2csv(table_name, header_values=header) sort_csv(csv_outfile)
def to_csv(self, sort=True, path=None): """Export table from xml engine to CSV file.""" for table_item in self.script_table_registry[self.script.name]: header = table_item[1].get_insert_columns(join=False, create=True) outputfile = os.path.normpath( os.path.join(path if path else '', os.path.splitext(os.path.basename(table_item[0]))[0] + '.csv')) csv_outfile = xml2csv(table_item[0], outputfile=outputfile, header_values=header) sort_csv(csv_outfile)
def test_xml2csv(): """Test xml2csv function. Creates a xml file and tests the md5 sum calculation. """ xml_file = create_file([ '<root>', '<row>', '<User>Alex</User>', '<Country>US</Country>', '<Age>25</Age>', '</row>', '<row>', '<User>Ben</User>', '<Country>US</Country>', '<Age>24</Age>', '</row>', '</root>' ], 'output.xml') output_xml = xml2csv(xml_file, "output_xml.csv", header_values=["User", "Country", "Age"]) obs_out = file_2list(output_xml) os.remove(output_xml) assert obs_out == ['User,Country,Age', 'Alex,US,25', 'Ben,US,24']
def test_xml2csv(): """Test xml2csv function. Creates a xml file and tests the md5 sum calculation. """ xml_file = create_file(['<root>', '<row>', '<User>Alex</User>', '<Country>US</Country>', '<Age>25</Age>', '</row>', '<row>', '<User>Ben</User>', '<Country>US</Country>', '<Age>24</Age>', '</row>', '</root>'], 'output.xml') output_xml = xml2csv(xml_file, "output_xml.csv", header_values=["User", "Country", "Age"]) obs_out = file_2list(output_xml) os.remove(output_xml) assert obs_out == ['User,Country,Age', 'Alex,US,25', 'Ben,US,24']
def to_csv(self, sort=True): """Export table from xml engine to CSV file.""" for table_item in self.script_table_registry[self.script.name]: header = table_item[1].get_insert_columns(join=False, create=True) csv_outfile = xml2csv(table_item[0], header_values=header) sort_csv(csv_outfile)