I have a text string containing XML data (though it has no header info) and I am attempting to populate a DataTable containing its elements. I am not receiving any error messages, however my DataTable contains 0 rows following the .ReadXml command. The Xml is as follows:
<items>
<item>
<Date>05-Feb-2008</Date>
<User>Unknown</User>
<Comment>Due date moved</Comment>
<Restricted>True</Restricted>
</item>
<item>
<Date>07-Nov-2008</Date>
<User>Unknown</User>
<Comment>Priority increased. Due date moved to end Oct</Comment>
<Restricted>False</Restricted>
</item>
</items>
And my code to create the DataTable is as follows:
Stream xmlStream = new MemoryStream();
StreamWriter writer = new StreamWriter(xmlStream);
string xml = (string)row["XmlComments"];
writer.Write(xml);
writer.Flush();
xmlStream.Position = 0;
DataTable xmlComments = new DataTable();
xmlComments.Columns.Add("User", typeof(string));
xmlComments.Columns.Add("Date", typeof(DateTime));
xmlComments.Columns.Add("Comment", typeof(string));
xmlComments.Columns.Add("OSG_Only", typeof(string));
xmlComments.ReadXml(xmlStream);
Could anyone shed any light on what I’m missing here?
Many thanks
This should work