如何使用C#将xml-stylesheet标签添加到XML文件?

Bog*_*iun 7 c# xml xslt

我需要在创建它时将以下代码添加到XML文件的开头:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="colors.xslt"?>
Run Code Online (Sandbox Code Playgroud)

我确定有一种方法,但我还没有找到它.我正在使用C#.谢谢

Rub*_*ias 18

XmlDocument.CreateProcessingInstruction方法

public static void Main()
{
    var doc = new XmlDocument();
    doc.AppendChild(doc.CreateProcessingInstruction(
        "xml-stylesheet", 
        "type='text/xsl' href='colors.xslt'"));
}
Run Code Online (Sandbox Code Playgroud)