C# Add element to XElement

 XElement xTotalTax = new XElement("totalTax");
                    XElement xInvoiceDiscountPercent = new XElement("invoiceDiscountPercent");
                    decimal dAmtIncVat = decimal.Parse(value.Element("amountIncludingVAT").Value);
                    decimal damount = decimal.Parse(value.Element("amount").Value);
                    decimal dInvDisAmt = decimal.Parse(value.Element("invoiceDiscountAmount").Value);
                    decimal dTotalTax = dAmtIncVat - damount;
                    xTotalTax.Value = dTotalTax.ToString();
                    decimal dInvDisPer = Math.Round(dInvDisAmt * 100 / (dInvDisAmt + damount), 2);
                    xInvoiceDiscountPercent.Value = dInvDisPer.ToString();
                    xHeader.Add(xTotalTax);
                    xHeader.Add(xInvoiceDiscountPercent);

requirements: add element for xHeader.

first step is to create new xEkement, e.g "totalTax", then set the value for element "totalTax", finally, add element.

猜你喜欢

转载自blog.csdn.net/u010081392/article/details/84648930
Add