Advertisement
Milotronik

LeerMiXML

Jun 7th, 2012
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ASP 3.16 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Xml;
  8.  
  9. public partial class LeerXml : System.Web.UI.Page
  10. {
  11.     protected void Page_Load(object sender, EventArgs e)
  12.     {
  13.         contenidoXml.InnerHtml = leerXML();
  14.     }
  15.  
  16.     public String leerXML()
  17.     {
  18.         String resultado = "";
  19.         String ruta = Server.MapPath("~");
  20.         try
  21.         {
  22.  
  23.             XmlDocument xDoc = new XmlDocument();
  24.             xDoc.Load(ruta + "\\miXml.xml");
  25.             XmlNodeList empleados = xDoc.GetElementsByTagName("empleados");
  26.             XmlNodeList listaEmpleado = ((XmlElement)empleados[0]).GetElementsByTagName("empleado");
  27.             resultado = "<b>Empleados:</b><br/>-----------------------------------------------------------------------<br/>";
  28.             foreach (XmlElement nodo in listaEmpleado)
  29.             {
  30.  
  31.                 XmlNodeList nId = nodo.GetElementsByTagName("id");
  32.  
  33.                 XmlNodeList nNombreCompleto = nodo.GetElementsByTagName("nombreCompleto");
  34.  
  35.                 XmlNodeList nCuit = nodo.GetElementsByTagName("cuit");
  36.  
  37.                 XmlNodeList nSector = nodo.GetElementsByTagName("sector");
  38.                 //XML AttributeCollection
  39.                 XmlAttributeCollection aSector = nSector[0].Attributes;
  40.  
  41.                 XmlNodeList nCupoAsignado = nodo.GetElementsByTagName("cupoAsignado");
  42.  
  43.                 XmlNodeList nCupoConsumido = nodo.GetElementsByTagName("cupoConsumido");
  44.                
  45.  
  46.                 resultado +=
  47.                     "Id:" + nId[0].InnerText +
  48.                     "<br/>Nombre Completo: " + nNombreCompleto[0].InnerText +
  49.                     "<br/>Cuit: " + nCuit[0].InnerText +
  50.                     "<br/>Sector: " + nSector[0].InnerText +
  51.                     "denominacion = " + aSector[0].InnerText +
  52.                     " id = " + aSector[1].InnerText +
  53.                     " valorSemaforo = " + aSector[2].InnerText +
  54.                     " colorSemaforo = " + aSector[3].InnerText +
  55.                     "<br/>cupoAsignado: " + nCupoAsignado[0].InnerText +
  56.                     "<br/>cupoConsumido: " + nCupoConsumido[0].InnerText +
  57.                     "<br/>-----------------------------------------------------------------------<br/>";
  58.             }
  59.  
  60.             XmlNodeList nSubsectores = xDoc.GetElementsByTagName("subsectores");
  61.             XmlNodeList nTotalCupoAsignadoSector = xDoc.GetElementsByTagName("totalCupoAsignadoSector");
  62.             XmlNodeList nTotalCupoConsumidoSector = xDoc.GetElementsByTagName("totalCupoConsumidoSector");
  63.             XmlNodeList nValorDial = xDoc.GetElementsByTagName("valorDial");
  64.  
  65.             resultado +=
  66.                 "Subsectores: " + nSubsectores[0].InnerText +
  67.                 "<br/>Total Cupo AsignadoSector: " + nTotalCupoAsignadoSector[0].InnerText +
  68.                 "<br/>Total Cupo Consumido: " + nTotalCupoConsumidoSector[0].InnerText +
  69.                 "<br/>Valor Dial: " + nValorDial[0].InnerText;
  70.         }
  71.         catch (Exception ex)
  72.         {
  73.             return ex.Message;
  74.         }
  75.         return resultado;
  76.  
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement