// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.IO; using System.Xml; using System.Xml.Xsl; using System.Xml.Serialization; public class C3 { public string f1; public string f2; public string f3; } class MainClass { private static void standard(C3 c3) { Console.WriteLine("Standard:"); XmlSerializer ser = new XmlSerializer(typeof(C3)); ser.Serialize(Console.Out, c3); Console.WriteLine(); } private static void transformed(C3 c3) { Console.WriteLine("Transformed:"); XmlSerializer ser = new XmlSerializer(typeof(C3)); StringWriter sw = new StringWriter(); ser.Serialize(sw, c3); XmlDocument doc = new XmlDocument(); doc.LoadXml(sw.ToString()); XslTransform xslt = new XslTransform(); xslt.Load("C:\\C3.xsl"); XmlTextWriter wrt = new XmlTextWriter(Console.Out); wrt.Formatting = Formatting.Indented; xslt.Transform(doc, null, wrt, null); Console.WriteLine(); } public static void Main(string[] args) { C3 c3 = new C3(); c3.f1 = "a"; c3.f2 = "bb"; c3.f3 = "ccc"; standard(c3); transformed(c3); } }