0

I have some code that create xml file on the fly. Sometimes the node has a value and sometimes not. I need to get open and closing tags <hour>12:00</hour> or <hour></hour> even there is no value but I can't find a solution. where the value is empty I am getting <hour />

XmlTextWriter writer = new XmlTextWriter(path + "/" + CustomerId + "/Data/" + CustomerId + ".xml", System.Text.Encoding.UTF8);
writer.WriteStartDocument(true);
writer.Formatting = Formatting.Indented;
writer.Indentation = 2;
writer.WriteStartElement("data");

if (paravalue == null || paravalue == "")
{
    writer.WriteStartElement(para);
    writer.WriteString("");
    writer.WriteEndElement();
}
else
{
    writer.WriteStartElement(para);
    writer.WriteString(paravalue);
    writer.WriteEndElement();
}
Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Elidotnet
  • 291
  • 3
  • 18

1 Answers1

0

Use WriteFullEndElement instead of WriteEndElement.

Szabolcs Dézsi
  • 8,743
  • 21
  • 29