我有一个现有的 xml 代码,我想使用 c# 将其转换为一个类?我已经尝试过了,但我很困惑。希望你能帮我一把。谢谢
XmlDocument doc1 = new XmlDocument();
XmlElement root = doc1.CreateElement("SqlCommand");
doc1.AppendChild(root);
XmlElement tblElem = doc1.CreateElement("Table");
tblElem.SetAttribute("TableName", ddl2.SelectedItem.Text);
root.AppendChild(tblElem);
for (int i = 0; i < GridView1.Rows.Count; i++)
{
XmlElement colElem = doc1.CreateElement("Columns");
if (((CheckBox)GridView1.Rows[i].FindControl("chkCol")).Checked)
{
colElem.SetAttribute("ColumnName", GridView1.Rows[i].Cells[3].Text);
tblElem.AppendChild(colElem);
}
if (((RadioButton)GridView1.Rows[i].FindControl("radkey")).Checked)
{
colElem.SetAttribute("PKey", ddl2.SelectedItem.Text + "." + GridView1.Rows[i].Cells[3].Text);
tblElem.AppendChild(colElem);
}
}
doc1.Save(Server.MapPath(@"XmlFile/") + "config.xml");