'Create C# Class to fit XML file [duplicate]
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>
Solution 1:[1]
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; }
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | jdweng |
