【发布时间】:2012-03-29 22:33:37
【问题描述】:
如何从 XML 中获取 DataType 特定的 DataTable
这是我的代码
string XMLReportFormat =@"<?xml version="1.0" encoding="utf-8" ?>
<Table>
<ReportBody>
<TableRow>
<ID>1</ID>
<ParentID>1</ParentID>
<Key>First1</Key>
</TableRow>
<TableRow>
<ID>4</ID>
<ParentID>1</ParentID>
<Key>FirstChild4</Key>
</TableRow>
</ReportBody>
</Table>";
StringReader sReader = new StringReader(XMLReportFormat);
DataSet ds = new DataSet();
if (sReader == null)
return null;
ds.ReadXml(sReader);
在这里,我将所有DataType 列都设为String。
我想要一些像ID 和ParentID 这样的列作为Integer
【问题讨论】:
-
您正在将此 xml 值设置为属性或其他内容?
-
@Vinicius:为什么财产会出现? ...我没有使用任何属性
-
因为如果您使用的是属性,您可以尝试将 xml 属性(例如:ID)的值解析为具有相同名称的属性的类型,例如。
标签: c# xml datatable dataset type-conversion