Custom DateTime formats when using DataSet.WriteXml in .NET

后端 未结 5 884
别跟我提以往
别跟我提以往 2020-12-06 13:03

I\'ve got an issue where I am writing a DataSet to XML that has a column of type DateTime and I want to control the output format.

DataSet data = LoadDataSet         


        
5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-06 13:46

    Apply XSLT transformation to DataSet: (from MSDN) (I believe you will find XSLT example to convert DateTime format, or see post on SO regarding XSLT and DateTIme formats)

    DataSet custDS = new DataSet("CustomerDataSet");
    XmlDataDocument xmlDoc = new XmlDataDocument(custDS); 
    
    XslTransform xslTran = new XslTransform();
    xslTran.Load("transform.xsl");
    
    XmlTextWriter writer = new XmlTextWriter("xslt_output.html", 
      System.Text.Encoding.UTF8);
    
    xslTran.Transform(xmlDoc, null, writer);
    writer.Close();
    

提交回复
热议问题