C# 将字符串写入位于appdata\local中的xml文件
我是c#新手,我想知道如何在appdata/local中的xml文件中的特定标记之间编写字符串C# 将字符串写入位于appdata\local中的xml文件,c#,xml,C#,Xml,我是c#新手,我想知道如何在appdata/local中的xml文件中的特定标记之间编写字符串 我想要达到的目标是: <content> <Package name="gaffersimulations-fale" active="true"/> </content> 使用xml linq: using System; using System.Collections.Generic; using System.
我想要达到的目标是:
<content>
<Package name="gaffersimulations-fale" active="true"/>
</content>
使用xml linq:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
XElement content = new XElement("content");
XElement package = new XElement("Package", new object[] {
new XAttribute("name", "gaffersimulations-fale"),
new XAttribute("active", "true")
});
content.Add(package);
}
}
}
嗨,除了顶部的“”之外,没有任何东西被写入文件。我什么都没写。您需要使用:content.Save(“文件名”);