Here is the C# code that serializes the entity:
XmlSerializer xmls = new XmlSerializer(typeof(SaleItem));
using (MemoryStream ms = new System.IO.MemoryStream())
{
xmls.Serialize(ms, si);
ms.Seek(0, SeekOrigin.Begin);
StreamReader tr = new StreamReader(ms);
return tr.ReadToEnd();
}
Anyway, sp_xml_preparedocument does not like the datetime value generated by the XmlSerializer. The only way I know of to get around this problem is to:
1) Hand walk the entity and create my own XML (don’t use XmlSerializer)
2) Parse the string and get rid of the milliseconds (after 3 characters) and the -06:00.
Either way seems kind of like a pain and does not flow very well. Does anybody have a better way to do this?
The problem are indeed the beyond millisecond resolution and the timezone indicator. Can you generate your value with milliseconds only and the timezone Z or no timezone instead? Use casting rules for that in SQL Server 2005. In SQL Server 2005, you can write:
declare @x xml
set @x = N'
select @x.value('xs:dateTime(/EndDateTime[1])', 'datetime')
Note that this however performs two casts, so if you can change the value generation, that would be better.
Alternatively, if you can provide a schema that types the element as xs:dateTime, you will not have to explicitly cast it to xs:dateTime.
No comments:
Post a Comment