【发布时间】:2012-11-28 23:38:17
【问题描述】:
我有一个包含 XML 数据的文本字符串(尽管它没有标题信息),我正在尝试填充一个包含其元素的 DataTable。我没有收到任何错误消息,但是我的 DataTable 在 .ReadXml 命令之后包含 0 行。 xml如下:
<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>
我创建数据表的代码如下:
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);
有人能解释一下我在这里缺少什么吗?
非常感谢
【问题讨论】: