المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : XML Mapping to CSV



C# Programming
01-04-2013, 04:50 AM
Hello,

I have a fixed XML table thats coming from a Web Service.
JOHNSON, DANIEL R. BMRES-550 Bank of America 123456 49,7560.8600
I need to convert the XML data to CSV. The data to be converted has commas. So the below method doesn't work:
using (StreamWriter writer = File.CreateText("C:\\username\\password\\Desktop\\Export.csv")) { DataSet ds = new DataSet(); ds.ReadXml(XmlReader.Create(new StringReader(myWebreference.GetWebServiceMethod("username", "password1", "Export", "Parameter4", DateTime.Today, DateTime.Today, "")))); writer.WriteLine(string.Join(",", ds.Tables["Loan"].Columns.Cast().Select(col => col.ColumnName).ToArray())); foreach (DataRow row in ds.Tables["Loan"].Rows) { writer.WriteLine(string.Join(",", row.ItemArray.Cast().ToArray())); } }