我想阅读下面的 XML 格式,只需要一些属性而不是全部。例如:
<Parts>
- <Part>
<Section>3003512</Section>
<Mark>RP-103</Mark>
<Length>4950</Length>
- <Components>
<Section>3003512</Section>
<Mark>RP-103</Mark>
<Length>4950</Length>
<Remark>System Generated </Remark>
<Components />
<Remark>No Comments </Remark>
</Part>
- <Part>
<Section>3003512</Section>
<Mark>RP-103</Mark>
<Length>4950</Length>
<Components />
<Remark>No Comments </Remark>
</Part>
</Parts>
我想只读部分并以表格格式标记。我正在使用下面的代码来阅读这个但是它给出了错误表架构'组件'已经存在。
DataTable dt = new DataTable();
DataColumn dc = new DataColumn("Mark");
DataColumn dc1 = new DataColumn("Sections ");
dt.Columns.Add(dc);
dt.Columns.Add(dc1);
DataSet dSet = new DataSet();
if (File.Exists(xmlpath2))
{
XmlTextReader Reader1 = new XmlTextReader(xmlpath2);
dSet.ReadXml(Reader1, XmlReadMode.Auto);
for (int i = 0; i < dSet.Tables[0].Rows.Count; i++)
{
DataRow rows = dSet.Tables[0].Rows[i];
DataRow myRow = dt.NewRow();
myRow["Mark"] = rows["Mark"];
myRow["Sections "] = rows["Sections "];
dt.Rows.Add(myRow);
}
GridView1.DataSource = dt;
GridView1.DataBind();
}