Serialize everything in a single line

0

I'm generating an xml from an NFSe, but I need to generate everything on a single line, even when I generate the signature. When I serialize, I do this:

StringWriter sw = new StringWriter();
            XmlTextWriter tw = new XmlTextWriter(sw);

            XmlSerializerNamespaces xsn = new XmlSerializerNamespaces();

            XmlSerializer ser = new XmlSerializer(typeof(GerarNfseEnvio));
            FileStream arquivo = new FileStream("E:\nota.xml", FileMode.CreateNew);
            xsn.Add("", "http://www.abrasf.org.br/nfse.xsd");
            arquivo.Flush();
            ser.Serialize(arquivo, gerar, xsn);
            arquivo.Close();

But it is indented and in several lines, I need everything in a single line, because the way I'm doing, I need to create a new file for each change, and I do this:

using (var writer = System.IO.File.CreateText("E:\notasemesp.xml"))
            {
                var doc = new XmlDocument { PreserveWhitespace = false };
                doc.Load("E:\nota.xml");
                writer.WriteLine(doc.InnerXml);
                writer.Flush();
            }

It is not possible to create a new file, for a new change, since until the end is made 3 changes, then it would be necessary to create 3 more xml, how can I correct this problem? Example: The way I serialize it looks like this:

<Rps>
  <IdentificacaoRps>
     <Numero>1</Numero>
      <Serie>999</Serie>
      <Tipo>1</Tipo>
  </IdentificacaoRps>
 <DataEmissao>2018-11-27</DataEmissao>
<Status>1</Status>

I need every change that I use Save to look like this:

 <Rps><IdentificacaoRps><Numero>1</Numero><Serie>999</Serie><Tipo>1</Tipo</IdentificacaoRps><DataEmissao>2018-11-27</DataEmissao<Status>1</Status></Rps>
    
asked by anonymous 28.11.2018 / 14:27

1 answer

1

One option is to use XDocument of System.Xml.Linq

 System.Xml.Linq.XDocument doc = System.Xml.Linq.XDocument.Load("E:\nota.xml");
 doc.Save("E:\notasemesp.xml", System.Xml.Linq.SaveOptions.DisableFormatting);
    
28.11.2018 / 15:55