The data that I am sending to convertStringToDataSet function is
<NewDataSet>\r\n <Table ID="Table1">
\r\n
<PATNAME>Doe,JaneN</PATNAME>\r\n
<LEVEL>175</LEVEL>\r\n
<WHEN>2007-09-13T23:00:00.0000000-05:00</WHEN>\r\n
<NOTE>New 180-day low -- ALERT: loss of 11.6 % in 123 days</NOTE>\r\n
<IS_BAD>32</IS_BAD>\r\n
<NAME>202a</NAME>\r\n
<ID>2459</ID>\r\n
<LASTNAME>Doe</LASTNAME>\r\n
<FIRSTNAME>Jane</FIRSTNAME>\r\n
<MIDDLENAME>N</MIDDLENAME>\r\n
</Table>\r\n <Table ID="Table2">
\r\n
<PATNAME>Face,SmileyE</PATNAME>\r\n
<LEVEL>124</LEVEL>\r\n
<WHEN>2007-10-16T23:00:00.0000000-05:00</WHEN>\r\n
<NOTE>New 180-day low -- ALERT: loss of 14.5 % in 86 days</NOTE>\r\n
<IS_BAD>32</IS_BAD>\r\n
<NAME>101b</NAME>\r\n
<ID>2736</ID>\r\n
<LASTNAME>Face</LASTNAME>\r\n
<FIRSTNAME>Smiley</FIRSTNAME>\r\n
<MIDDLENAME>E</MIDDLENAME>\r\n
</Table>\r\n</NewDataSet>
private DataSet convertStringToDataSet(string xmlString)
{
// Search for datetime values of the format
// --> 2004-08-22T00:00:00.0000000-05:00
string rp = @"(?\d{4}-\d{2}-\d{2})(?T\d{2}:\d{2}:\d{2}.\d{7}-)(?\d{2})(?:\d{2})";
// Replace UTC offset value
string fixedString = Regex.Replace( xmlString, rp, new MatchEvaluator( getHourOffset ) );
DataSet dataSet = new DataSet();
StringReader stringReader = new StringReader( fixedString );
dataSet.ReadXml( stringReader );
return dataSet;
}
private static string getHourOffset( Match m )
{
// Need to also account for Daylights Savings
// Time when calculating UTC offset value
string Date=m.Result( "${date}" );
DateTime dtLocal = DateTime.Parse( m.Result( "${date}" ) );
DateTime dtUTC = dtLocal.ToUniversalTime();
int hourLocalOffset = dtUTC.Hour - dtLocal.Hour;
int hourServer = int.Parse( m.Result( "${hour}" ) );
string newHour = ( hourServer + ( hourLocalOffset -
hourServer ) ).ToString( "0#" );
string retString = m.Result( "${date}" + "${time}" +
newHour + "${last}" );
return retString;
}
The Exception That I am getting The string was not recognized as a valid DateTime. There is a unknown word starting at index 2.