Usuário com melhor resposta
Como criar uma Objeto Serializavel que possa ser repetido. ! (Exigencia da DU-E Siscomex)

Pergunta
-
Estou trabalhando em um projeto, que ira criar o xml para envio a Siscomex (governo), da DU-E (Documento de Exportação), nele tem uma tag 'AddtionalInformation', com 3 propriedades dentro, até ai não teve problemas, mais no exemplo deles e Sql de dados vem mais de 1 conteudo para está tag, nao sei como gerar uma hierarquia de objetos que comporte isso.
O exemplo deles fica assim.
<!-- Forma de Exportação (CUS) -->
<AdditionalInformation>
<StatementCode>1001</StatementCode>
<StatementTypeCode>CUS</StatementTypeCode>
</AdditionalInformation>
<!-- Via especial de Transporte (TRA) -->
<AdditionalInformation>
<StatementCode>4001</StatementCode>
<StatementTypeCode>TRA</StatementTypeCode>
</AdditionalInformation>
<!-- Observações gerais (AAI) -->
<AdditionalInformation>
<StatementDescription languageID="">Observações gerais</StatementDescription>
<StatementTypeCode>AAI</StatementTypeCode>
</AdditionalInformation>No meu C# fiz para 1 nivel, como o manual do objeto mostrou....
AdditionalInformation
Respostas
-
Bom dia Carlos Alberto Pinto,
Por favor, veja se esses exemplos te ajudam:
========================================
Serialização de objetos em XML com C#
Veja neste artigo como serializar objetos em C# para o formato XML, através de um exemplo prático de exportação e importação de objetos para e de arquivos XML.public class Cliente { public string Nome { get; set; } public string Email { get; set; } public bool Exportar(string caminho) { try { FileStream stream = new FileStream(caminho, FileMode.Create); XmlSerializer serializador = new XmlSerializer(typeof(Cliente)); serializador.Serialize(stream, this); return true; } catch { return false; } } public static Cliente Importar(string caminho) { try { FileStream stream = new FileStream(caminho, FileMode.Open); XmlSerializer desserializador = new XmlSerializer(typeof(Cliente)); Cliente cliente = (Cliente)desserializador.Deserialize(stream); return cliente; } catch { return null; } } }
https://www.devmedia.com.br/serializacao-de-objetos-em-xml-com-csharp/28132
========================================
Como serializar um objeto para XML usando o Visual C#
using System; using System.IO; using System.Collections; using System.Xml.Serialization; public class Test{ static void Main(){ Test t = new Test(); t.SerializeCollection("coll.xml"); } private void SerializeCollection(string filename){ Employees Emps = new Employees(); // Note that only the collection is serialized -- not the // CollectionName or any other public property of the class. Emps.CollectionName = "Employees"; Employee John100 = new Employee("John", "100xxx"); Emps.Add(John100); XmlSerializer x = new XmlSerializer(typeof(Employees)); TextWriter writer = new StreamWriter(filename); x.Serialize(writer, Emps); } } public class Employees:ICollection{ public string CollectionName; private ArrayList empArray = new ArrayList(); public Employee this[int index]{ get{return (Employee) empArray[index];} } public void CopyTo(Array a, int index){ empArray.CopyTo(a, index); } public int Count{ get{return empArray.Count;} } public object SyncRoot{ get{return this;} } public bool IsSynchronized{ get{return false;} } public IEnumerator GetEnumerator(){ return empArray.GetEnumerator(); } public void Add(Employee newEmployee){ empArray.Add(newEmployee); } } public class Employee{ public string EmpName; public string EmpID; public Employee(){} public Employee(string empName, string empID){ EmpName = empName; EmpID = empID; } }
https://support.microsoft.com/pt-br/help/815813/how-to-serialize-an-object-to-xml-by-using-visual-c
========================================
Exemplos de Serialização XML
https://msdn.microsoft.com/pt-br/library/58a18dwa(v=vs.120).aspx
========================================
C# - Serializando Objetos para String e vice-versanamespace Serializar_Objetos { public class Pessoa { public string Nome { get; set; } public string Email { get; set; } public string ID { get; set; } } }
using System; using System.IO; using System.Xml.Serialization; namespace Serializar_Objetos { public static class Persistencia { public static string SerializaParaString<T>(this T valor) { try { XmlSerializer xml = new XmlSerializer(valor.GetType()); StringWriter retorno = new StringWriter(); xml.Serialize(retorno, valor); return retorno.ToString(); } catch { throw; } } public static object DeserializaParaObjeto(string valor, Type tipo) { try { XmlSerializer xml = new XmlSerializer(tipo); var valor_serealizado = new StringReader(valor); return xml.Deserialize(valor_serealizado); } catch { throw; } } } }
http://www.macoratti.net/16/02/c_serobj1.htm
========================================
Curiosidades:
========================================
Ler tags .xml repetidas em C#
https://social.msdn.microsoft.com/Forums/pt-BR/327f03c6-125a-498b-8798-13ce1df28eb6/ler-tags-xml-repetidas-em-c
========================================
Exemplos de elaboração de DU-E por XML
3. Exportação indireta utilizando notas de formação de lote
http://portal.siscomex.gov.br/conheca-o-portal/exemplos-de-elaboracao-de-du-e-por-xml
========================================
Exemplo de xml com justificativa para depuração estatística do DEAX
http://portal.siscomex.gov.br/conheca-o-portal/exemplo-de-xml-com-justificativa-para-depuracao-estatistica-do-deax
========================================
Import fiscal documents for Brazil
https://docs.microsoft.com/en-us/dynamics365/unified-operations/financials/localizations/latam-bra-import-fiscal-documents
========================================
Roteiro visual xml
http://portal.siscomex.gov.br/arquivos-ti-pucomex/roteiro-visual-xml/view
========================================
[]'s,
Fabio I.- Marcado como Resposta Filipe B CastroModerator segunda-feira, 15 de outubro de 2018 15:09
Todas as Respostas
-
Bom dia Carlos Alberto Pinto,
Por favor, veja se esses exemplos te ajudam:
========================================
Serialização de objetos em XML com C#
Veja neste artigo como serializar objetos em C# para o formato XML, através de um exemplo prático de exportação e importação de objetos para e de arquivos XML.public class Cliente { public string Nome { get; set; } public string Email { get; set; } public bool Exportar(string caminho) { try { FileStream stream = new FileStream(caminho, FileMode.Create); XmlSerializer serializador = new XmlSerializer(typeof(Cliente)); serializador.Serialize(stream, this); return true; } catch { return false; } } public static Cliente Importar(string caminho) { try { FileStream stream = new FileStream(caminho, FileMode.Open); XmlSerializer desserializador = new XmlSerializer(typeof(Cliente)); Cliente cliente = (Cliente)desserializador.Deserialize(stream); return cliente; } catch { return null; } } }
https://www.devmedia.com.br/serializacao-de-objetos-em-xml-com-csharp/28132
========================================
Como serializar um objeto para XML usando o Visual C#
using System; using System.IO; using System.Collections; using System.Xml.Serialization; public class Test{ static void Main(){ Test t = new Test(); t.SerializeCollection("coll.xml"); } private void SerializeCollection(string filename){ Employees Emps = new Employees(); // Note that only the collection is serialized -- not the // CollectionName or any other public property of the class. Emps.CollectionName = "Employees"; Employee John100 = new Employee("John", "100xxx"); Emps.Add(John100); XmlSerializer x = new XmlSerializer(typeof(Employees)); TextWriter writer = new StreamWriter(filename); x.Serialize(writer, Emps); } } public class Employees:ICollection{ public string CollectionName; private ArrayList empArray = new ArrayList(); public Employee this[int index]{ get{return (Employee) empArray[index];} } public void CopyTo(Array a, int index){ empArray.CopyTo(a, index); } public int Count{ get{return empArray.Count;} } public object SyncRoot{ get{return this;} } public bool IsSynchronized{ get{return false;} } public IEnumerator GetEnumerator(){ return empArray.GetEnumerator(); } public void Add(Employee newEmployee){ empArray.Add(newEmployee); } } public class Employee{ public string EmpName; public string EmpID; public Employee(){} public Employee(string empName, string empID){ EmpName = empName; EmpID = empID; } }
https://support.microsoft.com/pt-br/help/815813/how-to-serialize-an-object-to-xml-by-using-visual-c
========================================
Exemplos de Serialização XML
https://msdn.microsoft.com/pt-br/library/58a18dwa(v=vs.120).aspx
========================================
C# - Serializando Objetos para String e vice-versanamespace Serializar_Objetos { public class Pessoa { public string Nome { get; set; } public string Email { get; set; } public string ID { get; set; } } }
using System; using System.IO; using System.Xml.Serialization; namespace Serializar_Objetos { public static class Persistencia { public static string SerializaParaString<T>(this T valor) { try { XmlSerializer xml = new XmlSerializer(valor.GetType()); StringWriter retorno = new StringWriter(); xml.Serialize(retorno, valor); return retorno.ToString(); } catch { throw; } } public static object DeserializaParaObjeto(string valor, Type tipo) { try { XmlSerializer xml = new XmlSerializer(tipo); var valor_serealizado = new StringReader(valor); return xml.Deserialize(valor_serealizado); } catch { throw; } } } }
http://www.macoratti.net/16/02/c_serobj1.htm
========================================
Curiosidades:
========================================
Ler tags .xml repetidas em C#
https://social.msdn.microsoft.com/Forums/pt-BR/327f03c6-125a-498b-8798-13ce1df28eb6/ler-tags-xml-repetidas-em-c
========================================
Exemplos de elaboração de DU-E por XML
3. Exportação indireta utilizando notas de formação de lote
http://portal.siscomex.gov.br/conheca-o-portal/exemplos-de-elaboracao-de-du-e-por-xml
========================================
Exemplo de xml com justificativa para depuração estatística do DEAX
http://portal.siscomex.gov.br/conheca-o-portal/exemplo-de-xml-com-justificativa-para-depuracao-estatistica-do-deax
========================================
Import fiscal documents for Brazil
https://docs.microsoft.com/en-us/dynamics365/unified-operations/financials/localizations/latam-bra-import-fiscal-documents
========================================
Roteiro visual xml
http://portal.siscomex.gov.br/arquivos-ti-pucomex/roteiro-visual-xml/view
========================================
[]'s,
Fabio I.- Marcado como Resposta Filipe B CastroModerator segunda-feira, 15 de outubro de 2018 15:09
-
Fábio,
Estou precisando implementar a mesma integração aqui na empresa, porém não estou conseguindo me autenticar no serviço, pois o método pedido pela API é via Handshake SSL/TLS e eu não estou conseguindo sair do lugar. Tenho o certificado digital instalado na máquina, envio o mesmo na requisição, porém sempre obtenho retorno de erro 442.
Você já está autenticando no Portal Siscomex? Se sim, você consegue postar o código?
Obrigado!