I generated a class file from xmltosharp but I don't know how I can use it. I was doing all manually without class, but I will use class to be better in future codes.
I don't know how I can use it with linq, this is to generate a new XML file with complex structure, I need a start foot to follow with my steps.
My Class file as something like this (partial)
/*
Licensed under the Apache License, Version 2.0
http://www.apache.org/licenses/LICENSE-2.0
*/
using System;
using System.Xml.Serialization;
using System.Collections.Generic;
namespace Xml2CSharp
{ [XmlRoot(ElementName = "EnviarLoteRpsEnvio", Namespace = "http://www.issnetonline.com.br/webserviceabrasf/vsd/servico_enviar_lote_rps_envio.xsd")]
public class EnviarLoteRpsEnvio
{
[XmlElement(ElementName = "LoteRps", Namespace = "http://www.issnetonline.com.br/webserviceabrasf/vsd/servico_enviar_lote_rps_envio.xsd")]
public LoteRps LoteRps { get; set; }
[XmlElement(ElementName = "Signature", Namespace = "http://www.w3.org/2000/09/xmldsig#")]
public Signature Signature { get; set; }
[XmlAttribute(AttributeName = "xmlns")]
public string Xmlns { get; set; }
[XmlAttribute(AttributeName = "tc", Namespace = "http://www.w3.org/2000/xmlns/")]
public string Tc { get; set; }
}
}
My form file I'm trying this:
private void xmlbox_Click(object sender, EventArgs e)
{
EnviarLoteRpsEnvio el = new EnviarLoteRpsEnvio();
el.Xmlns = "tc";
el.LoteRps.CpfCnpj.Cnpj = "09581129000105";
XDocument xdoc = new XDocument();
xdoc.Add(new XDeclaration("1.0", "utf-8", "yes"));
xdoc.Element(el);
xdoc.Save("teste3.xml");
This is What I'm specting as XML file
<?xml version="1.0" encoding="utf-8"?>
<EnviarLoteRpsEnvio <?xml version="1.0" encoding="utf-8"?>
<EnviarLoteRpsEnvio xmlns="http://www.issnetonline.com.br/webserviceabrasf/vsd/servico_enviar_lote_rps_envio.xsd" xmlns:tc="http://www.issnetonline.com.br/webserviceabrasf/vsd/tipos_complexos.xsd">
<LoteRps>
<tc:NumeroLote>1</tc:NumeroLote>
<tc:CpfCnpj>
<tc:Cnpj>09581129000105</tc:Cnpj>
</tc:CpfCnpj>
<tc:InscricaoMunicipal></tc:InscricaoMunicipal>
<tc:QuantidadeRps>1</tc:QuantidadeRps>
<tc:ListaRps>
<tc:Rps>
<tc:InfRps>
<tc:IdentificacaoRps>
<tc:Numero>215</tc:Numero>
<tc:Serie>10</tc:Serie>
<tc:Tipo>1</tc:Tipo>
</tc:IdentificacaoRps>
</tc:Rps>
</tc:ListaRps>
</loteRps>