我的 XML 文件结构如下所示:
<SalaryDetails>
<Employee>
<Name>George Dsouza</Name>
<AnnualSalary>320000</AnnualSalary>
<DaysWorked>22</DaysWorked>
</Employee>
<Employee>
<Name>Jackie Parera</Name>
<AnnualSalary>300000</AnnualSalary>
<DaysWorked>19</DaysWorked>
</Employee>
...
</SalaryDetails>
我想将所有数据作为员工记录使用XmlDocument
.
所以我写了一个这样的循环:
XmlDocument xdcDocument = new XmlDocument();
xdcDocument.Load(@"D:\SalaryDetails.xml");
XmlElement xelRoot = xdcDocument.DocumentElement;
XmlNodeList xnlNodes = xelRoot.SelectNodes("/SalaryDetails/Employee");
foreach(XmlNode xndNode in xnlNodes)
{
//What to write here??
//My sql insert command will go here
}
AnnualSalary
并且DaysWorked
是整数。