Created
June 23, 2014 23:49
-
-
Save Fhernd/8bd7f3095532076c382c to your computer and use it in GitHub Desktop.
Conversión a tipos de la CLR desde el documento XML.
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.Xml.Schema; | |
using System.IO; | |
namespace Articulos.Preguntas | |
{ | |
public sealed class LecturaAtributosXML | |
{ | |
public static void Main() | |
{ | |
// Configuración XML para el lector: | |
XmlReaderSettings configXml = new XmlReaderSettings(); | |
configXml.ValidationType = ValidationType.Schema; | |
configXml.Schemas.Add ("urn:contrato-empleado", "FechaContrato.xsd"); | |
XmlReader lectorXml = XmlReader.Create ("FechaContrato.xml", configXml); | |
// Despaza el lector a la primera posición con contenido | |
// en el documento XML: | |
lectorXml.MoveToContent(); | |
// Lee el nodo anidado `fecha-contrato`: | |
lectorXml.ReadToDescendant("fecha-contrato"); | |
// `fecha-contrato` como una instancia de DateTime: | |
DateTime fechaContrato = lectorXml.ReadElementContentAsDateTime(); | |
Console.WriteLine ("Fecha después de seis meses del contrato: {0}", fechaContrato.AddMonths(6)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment