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.
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.
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);
}