Dries in the XML string, line break (\ n) sent whenever the field is empty!

0

I'm building a string that has an XML result, just below, and on receiving the other end, a line break character appears in the empty fields, I've already tried to use replace (), regex ... someone has a suggestion?

StringBuilder Sb = new StringBuilder();

Sb.Append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
Sb.Append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:v1=\"http://dominio.com.br/vv/operacao_lojas/optout/atualizar/SOAP/v1\">";
Sb.Append("<soapenv:Header/>");
Sb.Append("<soapenv:Body>");
Sb.Append("<v1:atualizarOptOut>");
Sb.Append("<codigoClienteCpf>{0}</codigoClienteCpf>");
Sb.Append("<codigoProduto>{1}</codigoProduto>");
Sb.Append("<statusEnvioEmail>{2}</statusEnvioEmail>");
Sb.Append("<statusEnvioSms>{3}</statusEnvioSms>");
Sb.Append("<descricaoEmailCliente>{4}</descricaoEmailCliente>");
Sb.Append("<numeroDddCelCliente>{5}</numeroDddCelCliente>");
Sb.Append("<numeroCelularCliente>{6}</numeroCelularCliente>");
Sb.Append("</v1:atualizarOptOut>");
Sb.Append("</soapenv:Body>");
Sb.Append("</soapenv:Envelope>");

var retorno = String.Format(Sb.ToString(),
obj.codigoClienteCpf,
obj.codigoProduto,
**CleanInput(obj.statusEnvioEmail.Trim()),
CleanInput(obj.statusEnvioSms.Trim()),
CleanInput(obj.descricaoEmailCliente.Trim())
CleanInput(obj.numeroDddCelCliente.Trim()),
CleanInput(obj.numeroCelularCliente.Trim())**).Replace("\n","");


private static string CleanInput(string strIn)
{
//Remove todos os caracteres não alphanuméricos exceto (.) pontos, (@) arrobas e (-) hífens
try
{
 return Regex.Replace(strIn, @"[^\w\.@-]", "",
                 RegexOptions.None, TimeSpan.FromSeconds(1.5));
}
catch (RegexMatchTimeoutException)
{

return String.Empty;
 }
}
    
asked by anonymous 13.08.2018 / 16:01

0 answers