Reputation: 61
XmlWriter in Visual Studio 2012,
How can I output the following:
<Amt>
<InstdAmt Ccy=”EUR”>340.00</InstdAmt>
</Amt>
The following does not work:
const string cur = "Ccy=" + @"""EUR";
writer.WriteStartElement("Amt");
writer.WriteElementString("InstdAmt", cur, "340.00");
writer.WriteEndElement();
Upvotes: 0
Views: 347
Reputation: 6549
When you want to write node attributes, you can use WriteAttributeString(string localName, string value)
.
This should produce the desired output
writer.WriteStartElement("Amt");
writer.WriteStartElement("InstdAmt");
writer.WriteAttributeString("Ccy", "EUR");
writer.WriteString("340.00");
writer.WriteEndElement();
writer.WriteEndElement();
See the XmlTextWriter reference for more options.
Upvotes: 2
Reputation: 6424
You have to call Close()
method of the XmlWriter
object in order to write to the file:
writer.Close()
Upvotes: 0