0

I have this XML file, how can I make a C# Class to fit it, so I can Deserialize it to a C# object.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                  xmlns:siat="https://siat.in.com/">
    <soapenv:Header/>
    <soapenv:Body>
        <siat:cuis>
            <SolicitudCuis>
                <codigoAmbiente>2</codigoAmbiente>
                <codigoModalidad>2</codigoModalidad>
                <codigoPuntoVenta>1</codigoPuntoVenta>
                <codigoSistema>6D26B339E99593D9E6EE26F</codigoSistema>
                <codigoSucursal>0</codigoSucursal>
                <nit>6088511016</nit>
            </SolicitudCuis>
        </siat:cuis>
    </soapenv:Body>
</soapenv:Envelope>
T.S.
  • 18,195
  • 11
  • 58
  • 78
JKarov
  • 1

1 Answers1

0

Try following :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;

namespace ConsoleApp1
{
    class Program
    {
        const string FILENAME = @"c:\temp\test.xml";
        static void Main(string[] args)
        {
            XmlReader reader = XmlReader.Create(FILENAME);
            XmlSerializer serializer = new XmlSerializer(typeof(Envelope));
            Envelope envelope = (Envelope)serializer.Deserialize(reader);
        }
    }
    [XmlRoot(ElementName = "Envelope", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
    public class Envelope
    {
        public Header Header { get; set; }
        public Body Body { get; set; }
    }
    public class Header
    {

    }
    public class Body
    {
        [XmlArray("cuis", Namespace = "https://siat.in.com/")]
        [XmlArrayItem("SolicitudCuis", Namespace = "")]
        public List<Cuis> Cuis { get; set; } 

    }
    public class Cuis
    {
        public int codigoAmbiente { get; set; }
        public int codigoModalidad { get; set; }
        public int codigoPuntoVenta { get; set; }
        public string codigoSistema { get; set; }
        public int acodigoSucursal { get; set; }
        public long nit { get; set; }

    }

}
jdweng
  • 33,250
  • 2
  • 15
  • 20