我有以下 XML:
<Account>
<nr>6134</nr>
<name>Summ</name>
<Accounting>
<income>200</income>
</Accounting>
<summincome>200</summincome>
</Account>
我尝试过但没有成功:
myXmlTextWriter2.WriteStartElement("Account");
myXmlTextWriter2.WriteAttributeString("nr", AccountNumber.ToString());
myXmlTextWriter2.WriteAttributeString("name", Name);
double summ=0;
foreach (AccountRecord ar in kp)
{
myXmlTextWriter2.WriteStartElement("Accounting");
myXmlTextWriter2.WriteAttributeString("income", ar.Amount.ToString());
myXmlTextWriter2.WriteEndElement();
summ += ar.Amount;
}
myXmlTextWriter2.WriteAttributeString("summincome", summ.ToString());
myXmlTextWriter2.WriteEndElement();
如您所见,我输入了一个 foreach 循环来计算总和并将其值分配给“summincome”。提前谢谢你的小费