public ActionResult GeracaoXML()
        {
            LoteInternacao l = BuscaXmL();
            string         a;

            using (StringWriter str = new StringWriter())
                using (XmlTextWriter writer = new XmlTextWriter(str))
                {
                    writer.WriteStartDocument();
                    writer.WriteStartElement("loteInternacao");
                    foreach (var i in l.Internacoes)
                    {
                        writer.WriteStartElement("Internacao");
                        writer.WriteElementString("situacao", i.Situacao);
                        writer.WriteElementString("caraterInternacao", i.CaraterInternacao);
                        writer.WriteElementString("numeroAtendimento", i.NumeroOperadora);
                        writer.WriteElementString("numeroAutorizacao", null);
                        writer.WriteElementString("dataInternacao", i.dataInternacao.ToString("yyyy-MM-ddTHH:mm:ss"));
                        writer.WriteElementString("dataAlta", null);
                        writer.WriteElementString("condicaoAlta", null);
                        writer.WriteElementString("dataAutorizacao", null);
                        writer.WriteElementString("codigoCidPrincipal", null);
                        writer.WriteElementString("internadoOutrasVezes", null);
                        writer.WriteElementString("reinternado", null);
                        writer.WriteElementString("recaida", null);

                        writer.WriteStartElement("Hospital");
                        writer.WriteElementString("codigo", null);
                        writer.WriteElementString("nome", null);
                        writer.WriteEndElement();



                        writer.WriteStartElement("Beneficiario");
                        writer.WriteElementString("codigo", i.Beneficiarios.Codigo.ToString());
                        writer.WriteElementString("nome", i.Beneficiarios.Nome);
                        writer.WriteElementString("dataNascimento", null);
                        writer.WriteElementString("sexo", null);
                        writer.WriteElementString("nomeMae", null);
                        writer.WriteElementString("cpf", null);
                        writer.WriteElementString("endereco", null);
                        writer.WriteElementString("recemNascido", null);
                        writer.WriteEndElement();


                        writer.WriteStartElement("Operadora");
                        writer.WriteElementString("codigo", i.Operadoras.Codigo.ToString());
                        writer.WriteElementString("nome", i.Operadoras.Nome);
                        writer.WriteElementString("sigla", null);
                        writer.WriteElementString("plano", null);
                        writer.WriteElementString("numeroCarteira", null);
                        writer.WriteElementString("dataValidade", null);
                        writer.WriteEndElement();


                        foreach (var m in i.Medicos)
                        {
                            writer.WriteStartElement("Medico");
                            writer.WriteElementString("nome", m.Nome);
                            writer.WriteElementString("ddd", null);
                            writer.WriteElementString("telefone", null);
                            writer.WriteElementString("email", null);
                            writer.WriteElementString("uf", null);
                            writer.WriteElementString("crm", m.Crm);
                            writer.WriteElementString("especialidade", null);
                            writer.WriteElementString("tipoAtuacao", null);
                            writer.WriteEndElement();
                        }


                        writer.WriteStartElement("CidSecundario");
                        do
                        {
                            writer.WriteElementString("codigoCidSecundario", null);
                        } while (writer.Equals("CidSecundario"));
                        writer.WriteEndElement();



                        writer.WriteStartElement("Procedimento");
                        do
                        {
                            writer.WriteElementString("codigoProcedimento", null);
                            writer.WriteElementString("dataAutorizacao", null);
                            writer.WriteElementString("dataExecucao", null);
                        } while (writer.Equals("Procedimento"));
                        writer.WriteEndElement();


                        writer.WriteStartElement("Cti");
                        writer.WriteElementString("dataInical", null);
                        writer.WriteElementString("dataFinal", null);
                        writer.WriteElementString("codigoCidPrincipal", null);
                        writer.WriteElementString("condiaoAlta", null);
                        writer.WriteElementString("uf", null);
                        writer.WriteElementString("crm", null);
                        writer.WriteElementString("codigoHospital", null);
                        writer.WriteElementString("nomeHospital", null);
                        writer.WriteEndElement();



                        writer.WriteStartElement("SuporteVentilatorio");
                        writer.WriteElementString("tipo", null);
                        writer.WriteElementString("tipoInvasivo", null);
                        writer.WriteElementString("local", null);
                        writer.WriteElementString("dataInicial", null);
                        writer.WriteElementString("dataFinal", null);
                        writer.WriteStartElement("CondicaoAdquiridaSuporteVentilatorio");
                        writer.WriteElementString("codigoCondicaoAdquirida", null);
                        writer.WriteElementString("dataOcorrencia", null);
                        writer.WriteEndElement();
                        writer.WriteEndElement();



                        writer.WriteStartElement("CondicaoAdquirida");
                        writer.WriteElementString("codigoCondicaoAdquirida", null);
                        writer.WriteElementString("dataOcorrencia", null);
                        writer.WriteEndElement();

                        writer.WriteStartElement("AltaAdministrativa");
                        writer.WriteElementString("numeroAtendimento", null);
                        writer.WriteElementString("numeroAutorizacao", null);
                        writer.WriteEndElement();


                        writer.WriteEndElement();
                    }
                    writer.WriteEndElement();

                    writer.Close();

                    a = str.ToString();
                }



            return(Content(a));
        }