Ver Mensaje Individual
  #3 (permalink)  
Antiguo 22/07/2015, 10:22
DavidMore93
 
Fecha de Ingreso: junio-2012
Mensajes: 4
Antigüedad: 11 años, 10 meses
Puntos: 0
Información Respuesta: Deserializar XML a modelo en MVC

Ciertamente en parte me ayudó aunque tuve que buscar como deserializar. Por si alguien tiene dudas dejo aquí el resultado:

He creado un modelo con las propiedades:
Código:
    public class Item
    {
        public string tag1{ get; set; }
        public string tag2{ get; set; }
        public string tag3{ get; set; }
    }
Y luego hago una lista de este modelo una vez deserializado el documento:

Código:
public void readXML(List<string> rssLinks)
        {
            foreach (var link in rssLinks)
            {
                XmlDocument doc = new XmlDocument();
                List<Item> items = new List<Item>();

                doc.Load(link);
                XmlNode channelN = doc.SelectSingleNode("/rss/channel");
                XmlNodeList itemsN = channelN.SelectNodes("item");
                foreach (var itemN in itemsN)
                {
                    items.Add(new Item()
                    {
                        tag1= node.Attributes.GetNamedItem("tag1").Value,
                        tag2= node.Attributes.GetNamedItem("tag2").Value,
                        tag3= node.Attributes.GetNamedItem("tag3").Value
                    });
                }
            }
        }
Un saludo.