1

Here is a sample of code for formatting dates for an XML in C#:

Datatable dt = Data.GetMyDataTable();

foreach(DataRow row in dt.Rows)
{
    //Create XElement with date
    XElement element = new XElement("MyElement", Convert.ToDateTime(row["MyDateColumn"]).ToString("yyyy-MM-dd")));
}

When I look at the XML file in the Visual Studio 2008 XML Visualizer while debugging the application it show the date in the correct format of "2011-09-27".

When I use the following DecisionSoft XML Schema Validator to validate against the XSD file, I get the following error:

cvc-datatype-valid.1.2.1: '20110927' is not a valid value for 'date'.

Why does the XML Visualizer in Visual Studio 2008 show the correct format and the DecisionSoft does not? Also, how can I modify my code to fix the issue?

Michael Kniskern
  • 24,792
  • 68
  • 164
  • 231

0 Answers0