|#710290 Author: Prasad kulkarni Member Level: Diamond Member Rank: 8 Date: 03/Apr/2013 Rating: Points: 4|
First of all you need to read the XML file then you need to create a CSV file and write content in it.
check following code snippet
//create CSV file using stream writer
System.IO.StreamWriter objSW = new System.IO.StreamWriter("Path of CSV Creation");
//read xml file using XMLDocument
XmlDocument objDOM = new XmlDocument();
objDOM.Load("XML file path");
XMLNodeList XNodeList = document.getElementByTagName("user");
for each (XMLNode XN in XNodeList )
//Write content to CSV
objSW.WriteLine(XN.ChildNodes.InnerText + "," + XN.ChildNodes.InnerText + "," + XN.ChildNodes.InnerText);
objSW = null;
Here your file is created successfully.
To download file you can use following link, i have write an article over it.
Hope it helps
Editor, DotNetSpider MVM
Microsoft MVP [ASP.NET/IIS]
|#710294 Author: Ram Member Level: Bronze Member Rank: 2009 Date: 03/Apr/2013 Rating: Points: 4|
protected string ConvertCSVFile(DataSet obj)
string InputXml = obj.GetXml();
string Strcsv = string.Empty;
XDocument docxml = XDocument.Parse(InputXml);
StringBuilder sb = new StringBuilder(100000);
foreach (XElement node in docxml.Descendants("User"))
foreach (XElement item in node.Elements())
sb.Remove(sb.Length - 1, 1);
Strcsv = sb.ToString();
Response.ContentType = "text/csv";
Response.ContentEncoding = Encoding.GetEncoding(0);
|#710311 Author: Bandhavi Member Level: Silver Member Rank: 308 Date: 03/Apr/2013 Rating: Points: 4|
Step 1: load XML data. You can copy and paste your XML data to the Source Data box, then click Load button. After you have done so, the Source Data box will turn into a graphical XML viewer and your XML data will be displayed as a node tree.
Step 2: select the XML data you want to convert. Use the graphical XML viewer to navigate the XML node tree, find the node you want and click the radio button. If the seleted node is a simple XML element, only the content of that element will be converted. If the selected the node is a complex XML element, the content of all its child nodes will be converted. If you want to convert the whole XML document, you can select the root node. Click the Convert button, the selected XML data will be converted to a plain text file.
You can repeat Step 2 many times by selecting different nodes of your XML document.
Choose the target file format, CSV or plain text, by clicking Options.
Options You can use the following options to make the converted text in the format you desire.
Field Separator: Field separators will make the converted text easy to read or parse. You can specify how to separate the converted data fields. The default separator is a space. You can change it to any string of characters;
Trim XML Format White Space: Some XML files contain spaces and line breakers for the purpose of formating so that the document can be displayed in a more readable pattern by a text editor. When converted to text, these formating white spaces may not be wanted. You can use this option to trim the unwanted white spaces.
Add Linebreakers to Rows: If you specify to trim formating white spaces, all the data fields will be converted to one long line. You can use this option to add a line breaker to the end of each row of the XML elements.