Reputation: 95
I need to generate XML file in following format:
<Field Name="TagName">value</Field>
I am using the XmlTextWriter. It works but closing tag looks like : </Field Name="TagName">
and I would like it to be </Field>
Below my function to create node.
private static void createNode(string fieldName, string fieldValue, XmlTextWriter writer)
{
writer.WriteStartElement("Field Name="+"\"" + fieldName + "\"");
writer.WriteString(fieldValue);
writer.WriteEndElement();
}
Can you tell me if there is any library for c# which allows me to generate the xml in the format I am expecting or should I modyfiy the XmlTextWriter? If so, how?
Upvotes: 0
Views: 364
Reputation: 239784
Don't try to add the attribute during the WriteStartElement
call - use WriteAttributeString
separately:
writer.WriteStartElement("Field");
writer.WriteAttributeString("Name",fieldName);
writer.WriteString(fieldValue);
writer.WriteEndElement();
Upvotes: 2