c#使用linq技术创建xml文件的小例子
- 作者: 姽婳94
- 来源: 51数据库
- 2021-08-25
using system;
using system.collections.generic;
using system.componentmodel;
using system.data;
using system.drawing;
using system.linq;
using system.text;
using system.windows.forms;
using system.io;
using system.xml;
using system.xml.linq;
namespace createxmlbylinq
{
public partial class frm_main : form
{
public frm_main()
{
initializecomponent();
}
static string strpath = "employee.xml";
//创建xml文件
private void button1_click(object sender, eventargs e)
{
xdocument doc = new xdocument(//创建xml文档对象
new xdeclaration("1.0", "utf-8", "yes"),//添加xml文件声明
new xelement(textbox1.text,//创建xml元素
new xelement(textbox2.text, new xattribute(textbox3.text, textbox10.text),//为xml元素添加属性
new xelement(textbox4.text, textbox5.text),
new xelement(textbox6.text, textbox7.text),
new xelement(textbox8.text, textbox9.text))
)
);
doc.save(strpath);//保存xml文档
messagebox.show("xml文件创建成功");
}
}
}
<?xml version="1.0" encoding="utf-8" standalone="true"?>
-<peoples> -<people id="001"> <name>123</name> <sex>123</sex> <salary>123</salary> </people> </peoples>
- C#通过fleck实现wss协议的WebSocket多人Web实时聊天(附源码)
- 团队城市未满足要求:MSBuildTools12.0_x86_Path 存在
- 使用 MSBuild.exe 在发布模式下构建 C# 解决方案
- 当我发布 Web 应用程序时,AfterPublish 脚本不运行
- 构建时 T4 转换的产品仅在下一个构建中使用
- ASP.NET Core Application (.NET Framework) for Windows x64 only error in project.assets.json
- 新的 .csproj 格式 - 如何将整个目录指定为“链接文件"到子目录?
- 如何将条件编译符号(DefineConstants)传递给 msbuild
- MSBuild 支持 Visual Studio 2017 RTM 中的 T4 模板
- NuGet 包还原找不到包,没有源
