Como você força o fechamento explícito de tags com o Linq XM
Esta é a mesma pergunta que:Explicit Element Fechando tags com o espaço para nome System.Xml.Linq
mas eu uso o Net 4.0 e as respostas não funcionam mai
O problema é que eu realmente salvei tags sem valores e meu XML de saída se parece com o seguinte:
<field/>
Mas o que eu preciso é sempre abrir e fechar a tag, ou seja,
<field></field>
QUESTÃ: como fazer isso
Edições1Adicionando nós vazios:
if (field_xml == null) // always true, because I create the file for the first time
{
field_xml = new XElement(XMLKeys.field,String.Empty);
table_xml.Add(field_xml);
}
field_xml.SetAttributeValue(XMLKeys.name, field_info.Name);
// ... setting some other attributes of this node
e mais tarde, salvando o xml:
var writer = new FullEndingXmlTextWriter(parameters.OutputFilename, Encoding.UTF8);
root_xml.Save(writer);
FullEndingXmlTextWriter é a classe especializada que The Evil Greebo apontou (é suposto forçar a tag de fechamento explícita