How to Replace XML C#

Asked

Viewed 189 times

0

I have a method that receives some parameters, I would like to replace some xml information, at the moment I can only remove and add new information

   private void CriacaoDoConfirmarLogin(string CaminhoArquivoParaLeitura, string NomeCaminhoParaArquivoSaida, string Desafio)
        {
            //remove o conteudo do corpo do arquivo de retorno do webservice
            //para que eu possa utilizar para enviar outros metodos
            string CaminhoCompletoArquivoConfirmacao = CaminhoArquivoParaLeitura;
            XmlDocument doc = new XmlDocument();
            doc.Load(CaminhoCompletoArquivoConfirmacao);
            var todosOsNos = doc.SelectNodes("//*");
            for (int i = 0; i < todosOsNos.Count; i++)
            {
                var element = todosOsNos[i];

                if(element.Name == "ServiceId")
                {
                    element.InnerText.Replace("SolicitaLogon", "ConfirmaLogon");
                }

                if (element.Name == "MsgDesc")
                {
                    element.InnerText.Replace("Solicitação do Desafio de Logon", "Confirmação do Desafio de Login");
                }


                if (element.Name == "Resposta")
                {
                    // pega o parent node
                    XmlNode parent = element.ParentNode;
                    // remove o node
                    parent.RemoveChild(element);

                    //adiciona o node de desafio
                    XmlElement desafioElemento = doc.CreateElement("DesafioAssinado");
                    desafioElemento.InnerText = Desafio;
                    parent.AppendChild(desafioElemento);

                    // grava a saida do arquivo
                    string newXML = doc.OuterXml;
                    doc.Save(NomeCaminhoParaArquivoSaida);
                }

            }

         }
  • Are you sure the cited session is to be your Session ID? and not another webservice identifier?

  • I supplemented my question, see if it’s clearer now, I appreciate the help

  • @Leandroangelo, adjust the question, see if you can help

  • @Leandroangelo, I added the code,

  • Your question is more and more confused, you have two webservices? ContextoLoginWebService and objWSProducao?

  • @Leandroangelo, I have a class "Contextologinwebservice " in my controller I call her, ie in my controler Login, I’m calling my "Contextologinwebservice "

Show 1 more comment

1 answer

0

Where you wrote

element.InnerText.Replace("SolicitaLogon", "ConfirmaLogon");

write

element.InnerText = element.InnerText.Replace("SolicitaLogon", "ConfirmaLogon");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.