I write an element in an XML file using XmlWriter
using (XmlWriter writer = XmlWriter.Create("test.x))
{
writer.WriteStartElement("Order");
writer.WriteEndElement();
}
which writes the following to the file
<Order>
</Order>
However, I want to write the following
<Order key="Name">
</Order>
WriteStartElement only takes one argument:
public void WriteStartElement(
string localName
)
So I guess I have to use a different function, but I can’t find which one. So ho can I add a key to an element?
You need to add an attribute named
key(since that’s what you seem to want to add – an attribute to theOrderelement):See
WriteAttributeString.