5/9/2023 0 Comments Turn csv into xml![]() ![]() Site design by Jonathan Reinink and Ignace Nyamagana Butera. Prior to converting your records collection into XML. Love this package ? Support its development! © Copyright The League of Extraordinary Packages. The XMLConverter converts a CSV records collection into a PHP DOMDocument. More than a format translator, FME has tools specifically designed for restructuring. Use League\Csv\XMLConverter use League\Csv\Statement use League\Csv\Reader $csv = Reader :: createFromPath ( '/path/to/prenoms.csv', 'r' ) $csv -> setDelimiter ( ' ' ) $csv -> setHeaderOffset ( 0 ) $stmt = ( new Statement ()) -> where ( function ( array $record ) ) -> offset ( 0 ) -> limit ( 2 ) $converter = ( new XMLConverter ()) -> rootElement ( 'csv' ) -> recordElement ( 'record', 'offset' ) -> fieldElement ( 'field', 'name' ) $records = $stmt -> process ( $csv ) $dom = new DOMDocument ( '1.0' ) $dom -> loadXML ( 'My CSV Document' ) $data = $converter -> import ( $records, $dom ) $dom -> appendChild ( $data ) $dom -> formatOutput = true $dom -> encoding = 'iso-8859-15' echo '', PHP_EOL echo htmlentities ( $dom -> saveXML ()) // // // // My CSV Document // // // // Anaïs // 137 // F // 2004 // // // Anaïs // 124 // F // 2005 // // // Create automated workflows that convert CSV data into the XML format. A possible solution is to first load the csv into Pandas and then convert it row by row into XML, as so: import pandas as pd df pd.readcsv untitled.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |