XML:如何将一个文件读入另一个文件 [英] XML: How to read one file into another

查看:27
本文介绍了XML:如何将一个文件读入另一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件:A.xml 包含如下内容:

I have a file: A.xml containing something like this:

<?xml version="1.0"?>
<headernode>

</headernode>

在 headernode 内部,我需要能够动态加载另一个名为 B.xml 的 xml 文件的内容,其中包含以下内容

Inside of the headernode i need to be able to dynamically load the contents of another xml file called B.xml containing the following

<?xml version="1.0"?>
<token>
<a>0</a>
</token>

我的问题是如何在 a.xml 的头节点中获取 B.xml 的内容?

My question is how do i get the contents of B.xml inside the header node of a.xml?

谢谢!

推荐答案

这似乎有效:

var header = XDocument.Load("a.xml");
var token = XElement.Load("b.xml");

var headerNode = header.Elements("headernode").First();
headerNode.Add(token);

Console.WriteLine(header.ToString()); 
/*
The above prints:

<headernode>
  <token>
    <a>0</a>
  </token>
</headernode>
*/

这篇关于XML:如何将一个文件读入另一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆