c# - 将字符串写入位于 appdata\local 中的 xml 文件
问题描述
我是 C# 新手,我想知道如何<Package name="gaffersimulations-fale" active="true"/>
在位于 appdata/local 的 xml 文件中的特定标签之间写入字符串。
我想要达到的目标:
<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);
}
}
}
推荐阅读
- reactjs - React 库以拖动和选择图库中的图像
- spring-mvc - Spring MVC - 分段上传图片返回 null
- numpy - PyTorch:用二维张量索引高维张量
- spring-boot - google appengine 的管理控制台可以集成到 spring-boot 项目中吗?
- python - Head 元素仅在第一页加载时呈现
- python - 如何在范围内绘制句子的长度
- c# - 重新启动应用程序时清除会话信息(asp.net core)
- python - 中心发散颜色为零
- c# - Azure Functions - 返回类型 HttpResponseMessage 和 IActionResult 之间的区别
- node.js - 如何在猫鼬中进行嵌套查询?