Blog de Francisco Velázquez

otro blog personal

Posts Tagged ‘serialize

Deserializar en C# ignorando DTD

leave a comment »

        public static object Deserialize(System.Type type, string data)
        {
            XmlSerializer xmlSerializer = new XmlSerializer(type);
            TextReader textReader = new StringReader(data);
            XmlReaderSettings settings = new XmlReaderSettings();
            settings.ProhibitDtd = false;
            settings.XmlResolver = null;
            XmlReader xmlReader = XmlTextReader.Create(textReader, settings);
            return xmlSerializer.Deserialize(xmlReader);
        }
Advertisements

Written by fravelgue

June 8, 2011 at 9:48 am

Posted in development

Tagged with , , ,

Serialize/Deserialize

leave a comment »

using System.IO;
 using System.Xml;
 using System.Xml.Serialization;

private string serialize(System.Type type, Object data)
 {
 XmlSerializer xmlSerializer = new XmlSerializer(type);
 System.IO.TextWriter writer = new System.IO.StringWriter();
 xmlSerializer.Serialize(writer, data);
 writer.Close();
 return writer.ToString();
 }

private object deserialize(System.Type type, string data)
 {
 XmlSerializer xmlSerializer = new XmlSerializer(type);
 TextReader textReader = new StringReader(data);
 XmlReader xmlReader = new XmlTextReader(textReader);
 return xmlSerializer.Deserialize(xmlReader);
 }

Written by fravelgue

September 19, 2006 at 9:52 am

Posted in development

Tagged with , , , ,