XmlCsvReader is an implementation of the .NET managed System.Xml.XmlReader base class which parses tab delimited .csv files and returns the data as a stream of XML elements. Both the source code for the class and a command line executable are provided.
Download the zip file including the
standalone executable and the full source code: XmlCsvReader.zip
See online demo at demo.aspx.
See also online
source.
The command line executable version has the following options:
XmlCsvReader [-a] [-c] [-root name] [-row name] [-names a,b,c,...] customer.csv result.xml
-a Specifies that you want attributes instead of subelements. -c Specifies that the first row contains column names. -d char Specifies the column delimiter character (default is 'auto' which means auto-detect the delimiter). Other possibilities are -d "," and -d "|" and -d "\t".
-root name Specifies the root element name (default is 'root'). -row name Specifies the row element name (default is 'row'). -names a,b,c Specifies the actual column names to use, separated by commas or spaces. If you also specify "-c" then the header row in the .csv file is simply ignored, and your custom column names are used instead. customer.csv The first file name specifies the .csv input file. If no file names are specified then it reads from standard input. result.xml The second file name specifies the output xml file. If no second file name is specified then it writes to standard output.
XmlCsvReader is a subclass of XmlReader so you can use it anywhere you can use the XmlReader, for example in loading an XmlDocument or DataSet. The XmlCsvReader has the following constructors:
public XmlCsvReader();public XmlCsvReader( Uri location,
XmlNameTable nametable);
public XmlCsvReader( Stream input,
Uri baseUri,
XmlNameTable nametable);
public XmlCsvReader( TextReader input,
Uri baseUri,
XmlNameTable nametable);
If you use the default constructor you must provide an input source either via the Href property or the TextReader property. You can customize the output XML via the following properties:
Please email bugs, feedback and/or feature requests to Chris Lovett.
Version | Date | Description |
---|---|---|
1.2 | January 16th 2004 | Fix handling of column names that are illegal XML names (for example, name contains a space). Added test suite. |
1.1 | June 21st 2003 | Fix bugs in handling of string literals. Fixed returning of attributes when loading XmlDocument |
1.0.3 | April 27th 2003 | Fix NameTable issues. |
1.0.2 | April 20th 2003 | Add manual setting for column delimiter. |
1.0.1 | March 10th 2003 | Fix bug in loading XmlCsvReader into an XmlDocument |
1.0.1105 | January 10th 2003 | Add support for setting custom column names. |
1.0 | August 15th 2002 | Initial version |