Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created June 23, 2014 23:11
Show Gist options
  • Save Fhernd/fe840151ad4bcb59293f to your computer and use it in GitHub Desktop.
Save Fhernd/fe840151ad4bcb59293f to your computer and use it in GitHub Desktop.
Lectura de atributos de un nodo con XmlReader en C#.
using System;
using System.Xml;
using System.IO;
namespace Articulos.Preguntas
{
public sealed class LecturaAtributosXML
{
public static void Main()
{
XmlReader lectorXml = XmlReader.Create ("almacen2.xml");
while (lectorXml.Read())
{
// Muestra los atributos del nodo actual:
if (lectorXml.HasAttributes)
{
Console.WriteLine ("Atributos de <{0}>", lectorXml.Name);
for (int i = 0; i < lectorXml.AttributeCount; ++i)
{
Console.WriteLine (" {0}", lectorXml[i]);
}
}
// Desplaza el lector a la posición inicial:
lectorXml.MoveToElement();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment