tags:

views:

135

answers:

1

I have code that serializes a complex object to XML and saves it as a file, is there a quick way to include a style sheet in the xml during the serialization?

Using C# and .net framework v2.

+4  A: 

You can use an XmlWriter and WriteProcessingInstruction :

    XmlSerializer s = new XmlSerializer(typeof(myObj));
    using (XmlWriter w = XmlWriter.Create(@"c:\test.xml"))
    {
        w.WriteProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" href=\"USED-FILE.xsl\"");
        s.Serialize(w, myObj);
    }
bruno conde
Thanks Bruno, very good answer! Tried it and it works....
JL