// 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 C1 { public C2 c2; } public class C2 { public string s; } class MainClass { private static void standard(C1 c1) { Console.WriteLine("Standard:"); XmlSerializer ser = new XmlSerializer(typeof(C1)); ser.Serialize(Console.Out, c1); Console.WriteLine(); } private static void transformed(C1 c1) { Console.WriteLine("Transformed:"); XmlSerializer ser = new XmlSerializer(typeof(C1)); StringWriter sw = new StringWriter(); ser.Serialize(sw, c1); XmlDocument doc = new XmlDocument(); doc.LoadXml(sw.ToString()); XslTransform xslt = new XslTransform(); xslt.Load("C:\\C1.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) { C1 c1 = new C1(); c1.c2 = new C2(); c1.c2.s = "test"; standard(c1); transformed(c1); } }