Search code examples
c#xmllinq-to-xmlxelement

XML element - Formatting Tag


I am using

new XElement("InstdAmt", "1000")

However, I would like to add the currency in the first tag as shown below. How could I do this please?

Only using the first tag

new XElement("InstdAmt Ccy=EUR", "1000")

so I can get this result

<InstdAmt Ccy="EUR">1000</InstdAmt>

Solution

  • Just add an attribute:

     new XElement("InstdAmt", new XAttribute("Ccy", "Eur"), "1000");