public static XmlDocument Serialize( string testName, object obj, Encoding encoding, MappingAction action) { Stream stm = new MemoryStream(); XmlTextWriter xtw = new XmlTextWriter(stm, Encoding.UTF8); xtw.Formatting = Formatting.Indented; xtw.Indentation = 2; xtw.WriteStartDocument(); XmlRpcSerializer ser = new XmlRpcSerializer(); ser.Serialize(xtw, obj, action); xtw.Flush(); //Console.WriteLine(testName); stm.Position = 0; TextReader trdr = new StreamReader(stm, new UTF8Encoding(), true, 4096); String s = trdr.ReadLine(); while (s != null) { //Console.WriteLine(s); s = trdr.ReadLine(); } stm.Position = 0; XmlDocument xdoc = new XmlDocument(); xdoc.PreserveWhitespace = true; xdoc.Load(stm); return xdoc; }
public static XmlReader Serialize(string testName, object obj, Encoding encoding, MappingActions actions) { Stream stm = new MemoryStream(); var xtw = XmlRpcXmlWriter.Create(stm, new XmlRpcFormatSettings()); xtw.WriteStartDocument(); var ser = new XmlRpcSerializer(); ser.Serialize(xtw, obj, actions); xtw.Flush(); stm.Position = 0; return(XmlRpcXmlReader.Create(stm)); }
public static XmlReader Serialize( string testName, object obj, Encoding encoding, MappingActions actions) { Stream stm = new MemoryStream(); XmlWriter xtw = XmlRpcXmlWriter.Create(stm, new XmlRpcFormatSettings()); xtw.WriteStartDocument(); XmlRpcSerializer ser = new XmlRpcSerializer(); ser.Serialize(xtw, obj, actions); xtw.Flush(); stm.Position = 0; XmlReader rdr = XmlRpcXmlReader.Create(stm); return rdr; }
public static string SerializeToString( string testName, object obj, MappingAction action) { StringWriter strwrtr = new StringWriter(); XmlTextWriter xtw = new XmlTextWriter(strwrtr); // xtw.Formatting = formatting; // xtw.Indentation = indentation; xtw.WriteStartDocument(); XmlRpcSerializer ser = new XmlRpcSerializer(); ser.Serialize(xtw, obj, action); xtw.Flush(); //Console.WriteLine(testName); //Console.WriteLine(strwrtr.ToString()); return strwrtr.ToString(); }
public static string SerializeValue(object value, bool indent) { var memStm = new MemoryStream(); var writer = XmlRpcXmlWriter.Create( memStm, new XmlRpcFormatSettings { OmitXmlDeclaration = true, UseIndentation = indent }); var serializer = new XmlRpcSerializer(); serializer.Serialize(writer, value, new MappingActions { NullMappingAction = NullMappingAction.Error }); writer.Flush(); memStm.Position = 0; return(new StreamReader(memStm).ReadToEnd()); }
public static string SerializeValue(object value, bool indent) { var memStm = new MemoryStream(); var writer = XmlRpcXmlWriter.Create( memStm, new XmlRpcFormatSettings { OmitXmlDeclaration = true, UseIndentation = indent }); var serializer = new XmlRpcSerializer(); serializer.Serialize(writer, value, new MappingActions { NullMappingAction = NullMappingAction.Error }); writer.Flush(); memStm.Position = 0; return new StreamReader(memStm).ReadToEnd(); }