gpt4 book ai didi

c# - 使用 c# 在现有 xml 文件的开头和结尾添加节点

转载 作者:太空宇宙 更新时间:2023-11-03 12:27:46 26 4
gpt4 key购买 nike

我通过 API 调用生成了一个 XML 文件,然后我尝试使用 ssis 中的 XML 源组件读取该文件,但它是只读数据集,除了文件中包含的所有数据。

这是我的文件

<?XML version 1.0 >
<ABC>
<a>info<a/>
<ABC/>

但是我想要像下面这样的文件然后只有我可以使用组件轻松读取文件我们可以对单个文件手动操作文件,但不能对千个文件进行手动操作

<?XML Version 1.0>
<X>
<ABC>
<a>info <a/>
<ABC/>
</X>

如何将“X”节点添加到现有文件中。

我对 .Net 技术了解不多。

请尽早帮助我。

谢谢基兰库马尔

最佳答案

使用 xml 链接

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)
{
string xml =
"<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
"<ABC>" +
"<a>info</a>" +
"</ABC>";
XDocument doc = XDocument.Parse(xml);

XElement root = doc.Root;
root.ReplaceWith(new XElement("X", root));
}
}
}

关于c# - 使用 c# 在现有 xml 文件的开头和结尾添加节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43949491/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com