如何为~50 xml文件添加进程指令?
<?xml-stylesheet type="text/xsl" href="Sample.xsl"?>
Run Code Online (Sandbox Code Playgroud)
如果我追加节点,它会被添加到文件的末尾,但它必须是第一个.
我会使用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");
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2376 次 |
| 最近记录: |