Advertisement
Fhernd

LecturaElementosXML.cs

Jul 22nd, 2014
1,672
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.25 KB | None | 0 0
  1. using System;
  2. using System.Xml;
  3. using System.IO;
  4.  
  5. namespace Articulos.Preguntas
  6. {
  7.     public sealed class LecturaElementosXML
  8.     {
  9.         public static void Main()
  10.         {
  11.             XmlReader lectorXml = XmlReader.Create ("libros.xml");
  12.            
  13.             // Este método obvia los nodos que no son parte del contenido, y pasa
  14.             // directamente a nodos de contenido:
  15.            
  16.             while (lectorXml.Read())
  17.             {
  18.                 if (lectorXml.IsStartElement())
  19.                 {
  20.                     Console.WriteLine ("<{0}> ", lectorXml.Name);
  21.                 }
  22.                 else
  23.                 {
  24.                     Console.Write ("<{0}> ", lectorXml.Name);
  25.                    
  26.                     // Lee el inicio de la marca:
  27.                     lectorXml.Read();
  28.                    
  29.                     // Lectura de elementos anidados:
  30.                     if (lectorXml.IsStartElement())
  31.                     {
  32.                         Console.Write ("\t<{0}>", lectorXml.Name);
  33.                     }
  34.                    
  35.                     // Lee el texto del elemento:
  36.                     Console.WriteLine (lectorXml.ReadString());
  37.                 }
  38.             }
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement