Created
June 14, 2016 01:11
-
-
Save Fhernd/b2ce66ca433aa9ce121b580613679556 to your computer and use it in GitHub Desktop.
Uso de versiones sobrecargadas de XElement.Load. [OrtizOL]
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.IO; | |
using System.Xml; | |
using System.Xml.Linq; | |
namespace Recetas.CSharp.R0613 | |
{ | |
public class UsoLoad | |
{ | |
public static void Main() | |
{ | |
// Ruta de archivo XML: | |
string rutaArchivoXml = "CatalogoProductos.xml"; | |
// Carga de XML por medio de su nombre de archivo: | |
Console.WriteLine ("\nUso de versión Load(String):"); | |
XElement elementoRaiz = XElement.Load(rutaArchivoXml); | |
Console.WriteLine (elementoRaiz); | |
Console.WriteLine ("\nPresione Enter para continuar..."); | |
Console.ReadLine (); | |
// Carga a través de un flujo: | |
Console.WriteLine ("\nUso de versión Load(Stream):"); | |
FileStream flujo = File.OpenRead(rutaArchivoXml); | |
elementoRaiz = XElement.Load(flujo); | |
Console.WriteLine (elementoRaiz); | |
Console.WriteLine ("\nPresione Enter para continuar..."); | |
Console.ReadLine (); | |
// Carga a través de un objeto TextReader: | |
Console.WriteLine ("\nUso de versión Load(TextReader):"); | |
TextReader lector = new StreamReader(rutaArchivoXml); | |
elementoRaiz = XElement.Load(lector); | |
Console.WriteLine (elementoRaiz); | |
Console.WriteLine ("\nPresione Enter para continuar..."); | |
Console.ReadLine (); | |
// Carga a través de XmlReader: | |
Console.WriteLine ("\nUso de versión Load(XmlReader):"); | |
XmlReader lectorXml = new XmlTextReader(new StreamReader(rutaArchivoXml)); | |
elementoRaiz = XElement.Load(lectorXml); | |
Console.WriteLine (elementoRaiz); | |
Console.WriteLine ("\nPresione Enter para continuar...\n"); | |
Console.ReadLine (); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment