Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Xml;
- public partial class LeerXml : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- contenidoXml.InnerHtml = leerXML();
- }
- public String leerXML()
- {
- String resultado = "";
- String ruta = Server.MapPath("~");
- try
- {
- XmlDocument xDoc = new XmlDocument();
- xDoc.Load(ruta + "\\miXml.xml");
- XmlNodeList empleados = xDoc.GetElementsByTagName("empleados");
- XmlNodeList listaEmpleado = ((XmlElement)empleados[0]).GetElementsByTagName("empleado");
- resultado = "<b>Empleados:</b><br/>-----------------------------------------------------------------------<br/>";
- foreach (XmlElement nodo in listaEmpleado)
- {
- XmlNodeList nId = nodo.GetElementsByTagName("id");
- XmlNodeList nNombreCompleto = nodo.GetElementsByTagName("nombreCompleto");
- XmlNodeList nCuit = nodo.GetElementsByTagName("cuit");
- XmlNodeList nSector = nodo.GetElementsByTagName("sector");
- //XML AttributeCollection
- XmlAttributeCollection aSector = nSector[0].Attributes;
- XmlNodeList nCupoAsignado = nodo.GetElementsByTagName("cupoAsignado");
- XmlNodeList nCupoConsumido = nodo.GetElementsByTagName("cupoConsumido");
- resultado +=
- "Id:" + nId[0].InnerText +
- "<br/>Nombre Completo: " + nNombreCompleto[0].InnerText +
- "<br/>Cuit: " + nCuit[0].InnerText +
- "<br/>Sector: " + nSector[0].InnerText +
- "denominacion = " + aSector[0].InnerText +
- " id = " + aSector[1].InnerText +
- " valorSemaforo = " + aSector[2].InnerText +
- " colorSemaforo = " + aSector[3].InnerText +
- "<br/>cupoAsignado: " + nCupoAsignado[0].InnerText +
- "<br/>cupoConsumido: " + nCupoConsumido[0].InnerText +
- "<br/>-----------------------------------------------------------------------<br/>";
- }
- XmlNodeList nSubsectores = xDoc.GetElementsByTagName("subsectores");
- XmlNodeList nTotalCupoAsignadoSector = xDoc.GetElementsByTagName("totalCupoAsignadoSector");
- XmlNodeList nTotalCupoConsumidoSector = xDoc.GetElementsByTagName("totalCupoConsumidoSector");
- XmlNodeList nValorDial = xDoc.GetElementsByTagName("valorDial");
- resultado +=
- "Subsectores: " + nSubsectores[0].InnerText +
- "<br/>Total Cupo AsignadoSector: " + nTotalCupoAsignadoSector[0].InnerText +
- "<br/>Total Cupo Consumido: " + nTotalCupoConsumidoSector[0].InnerText +
- "<br/>Valor Dial: " + nValorDial[0].InnerText;
- }
- catch (Exception ex)
- {
- return ex.Message;
- }
- return resultado;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement