Create XML file

Asked

Viewed 483 times

0

I am trying to create an XML but it is causing the following error:

An Exception of type 'System.Invalidoperationexception' occurred in System.xml.dll but was not handled in user code

Additional information: There was an error generating the XML Document.

Code:

 public Boolean GerarArquivoExportacaoOff(String caminhoArquivo)
        {
            Encoding iso_8859_1 = Encoding.GetEncoding("iso-8859-1");
            StreamWriter streamWriter = new StreamWriter(caminhoArquivo, true, iso_8859_1, 100000);

            List<OFFLINE_TABELAS> offline_TabelasList = getListaTabelasAlteradas(); // Seleciona tabelas alteradas

            foreach (OFFLINE_TABELAS Entity_tabelas in offline_TabelasList)
            {
                var lista = getDados(Entity_tabelas.TABELA); // Obtem entidade a partir do nome da tabela


                System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(lista.GetType());

                using (TextWriter textWriter = new StreamWriter("D:/usuarios.xml"))
                {
                    //Definir o Type e o elemento raiz do XML (usuarios)
                    XmlSerializer ser = new XmlSerializer(lista.GetType(), new XmlRootAttribute("usuarios"));

                    //Serializar o list para o TextWriter e salvar os dados no XML
                    ser.Serialize(textWriter, lista);
                }
}
return true
} 

What’s wrong with that ?

  • Not knowing where the error occurs is difficult to help. I take this opportunity to say that I hope this method is not ready. A method that always returns true doesn’t make sense.

  • the error of this part: be.Serialize(textWriter, list);

  • Put the stack trace , I think it’ll be easier to understand.

  • You can put XML in your question, or somewhere to download?

  • instead of var list, I passed the entity and it worked, but I need you to dynamically do all entities and not specifically one. ex: List<ED_SERIES> list = list

No answers

Browser other questions tagged

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