可以将XSLT样式表添加到序列化的XML文档中吗? [英] Possible to add a XSLT Stylesheet to a serialized XML document?
本文介绍了可以将XSLT样式表添加到序列化的XML文档中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有将复杂对象序列化为XML并将其保存为文件的代码,有没有一种快速的方法在序列化期间将样式表包含在xml中?
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?
使用C#和.net框架v2.
Using C# and .net framework v2.
推荐答案
您可以使用 XmlWriter
和 WriteProcessingInstruction
:
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);
}
这篇关于可以将XSLT样式表添加到序列化的XML文档中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文