lovablebox

学点东西...

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

留着备用

public void Transfer(string inXmlFilename, string outCSVFilename)
  {
   // open or create
   FileStream fileCsv = new FileStream(outCSVFilename,FileMode.OpenOrCreate,FileAccess.Write);

   StreamWriter writerCsv = new StreamWriter(fileCsv);
   StreamReader readerXml=new StreamReader(inXmlFilename);
   
   XmlDataDocument datadoc = new XmlDataDocument();    
   datadoc.DataSet.ReadXml(readerXml);

   // read each test case, write to CSV file
   for (int i= 0; i < datadoc.ChildNodes[0].ChildNodes.Count; i++)
   {
    string strCsvLine = "";
    for (int j=0; j < datadoc.ChildNodes[0].ChildNodes[i].ChildNodes.Count; j++)
    {
     string strText = datadoc.ChildNodes[0].ChildNodes[i].ChildNodes[j].InnerText;   
     strCsvLine += strText.Replace(",", ".") + ",";
    }

    writerCsv.WriteLine(strCsvLine);
   }
   
   readerXml.Close();
   writerCsv.Close();
  }

posted on 2012-08-07 14:48  lovablebox  阅读(902)  评论(0编辑  收藏  举报