繁体   English   中英

如何在C#中将过程指令添加到XML文件

[英]How to add Process Instruction to an XML file in C#

如何向约50个xml文件添加过程指令?

 <?xml-stylesheet type="text/xsl" href="Sample.xsl"?> 

如果我追加节点,则将其添加到文件的末尾,但它必须是第一个。

我将使用LINQ to XML:

using System;
using System.Xml.Linq;

public class Test
{
    static void Main()
    {
        XDocument doc = XDocument.Load("test.xml");
        var proc = new XProcessingInstruction
            ("xml-stylesheet", "type=\"text/xsl\" href=\"Sample.xsl\"");
        doc.Root.AddBeforeSelf(proc);
        doc.Save("test2.xml");
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM