Save XML without formatting

1

I need to generate xml , however without jumping line, the way I generate it is all indented, how do I save without skipping line?

document.LoadXml(soapEnvelope);
document.Save(@"E:\nota.xml");

I tried this code below:

XDocument document = XDocument.Load("arquivo.xml");
document.Save("arquivo2.xml", SaveOptions.DisableFormatting);

However, the option SaveOptions does not appear, I use ASP.NET CORE . This is the whole method:

private void montaEnvelope(HttpWebRequest webRequest, XmlDocument document)
{
     string soapEnvelope = string.Empty;
     soapEnvelope += "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ws=\"http://ws.issweb.fiorilli.com.br/\" xmlns:xd=\"http://www.w3.org/2000/09/xmldsig#\">";
     soapEnvelope += "<soapenv:Header/><soapenv:Body><ws:gerarNfse>";
     soapEnvelope += document.LastChild.OuterXml.Replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>", string.Empty);
     soapEnvelope += "<username>01001001000113</username><password>123456</password></ws:gerarNfse></soapenv:Body></soapenv:Envelope>";

     MemoryStream stream = stringToStream(soapEnvelope);
     webRequest.ContentLength = stream.Length;
     Stream requestStream = webRequest.GetRequestStream();
     stream.WriteTo(requestStream);

     document.LoadXml(soapEnvelope);
     document.Save(@"E:\nota.xml");
     XDocument document1 = XDocument.Load(@"E:\nota.xml");
     this.XmlDocNFSe = document;
}
    
asked by anonymous 27.11.2018 / 14:43

1 answer

2

You are confused by the classes, which you are using by the method parameter is XmlDocument which does not have the overload with the SaveOptions parameter, but there is a way to save XmlDocument in> Unformatted :

Example:

XmlDocument doc = new XmlDocument();

using(XmlTextWriter wr = new XmlTextWriter(fileName, Encoding.UTF8))
{
    wr.Formatting = Formatting.None;
    doc.Save(wr);
}

Reference code: Is there any way to save an XmlDocument without indentation and line returns?

That is, XDocument is the class that has an overload with SaveOptions , different from what's in your code.

Reference: Is there any way to save an XmlDocument without indentation and line returns?     

27.11.2018 / 21:27