Created
June 23, 2014 22:44
-
-
Save Fhernd/f6b9e984171f75e6ae5e to your computer and use it in GitHub Desktop.
Lectura de los nodos de un archivo XML con XmlReader. En C#.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Xml; | |
using System.IO; | |
namespace Articulos.Preguntas | |
{ | |
public sealed class LecturaElementosXML | |
{ | |
public static void Main() | |
{ | |
XmlReader lectorXml = XmlReader.Create ("libros.xml"); | |
// Este método obvia los nodos que no son parte del contenido, y pasa | |
// directamente a nodos de contenido: | |
while (lectorXml.Read()) | |
{ | |
if (lectorXml.IsStartElement()) | |
{ | |
Console.WriteLine ("<{0}> ", lectorXml.Name); | |
} | |
else | |
{ | |
Console.Write ("<{0}> ", lectorXml.Name); | |
// Lee el inicio de la marca: | |
lectorXml.Read(); | |
// Lectura de elementos anidados: | |
if (lectorXml.IsStartElement()) | |
{ | |
Console.Write ("\t<{0}>", lectorXml.Name); | |
} | |
// Lee el texto del elemento: | |
Console.WriteLine (lectorXml.ReadString()); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment