转换XML节点到使用C#属性 [英] Converting XML nodes into attributes using C#

查看:112
本文介绍了转换XML节点到使用C#属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有被加载到一个XMLDocument一个XML字符串,一个类似如下:

I have an XML string that is loaded into an XMLDocument, similar to the one listed below:

  <note>
   <to>You</to> 
   <from>Me</from> 
   <heading>TEST</heading> 
   <body>This is a test.</body> 
  </note>



我想文本节点转换为属性(使用C#),所以它看起来是这样的:

I would like to convert the text nodes to attributes (using C#), so it looks like this:

<note to="You" from="Me" heading="TEST" body="This is a test." />



任何信息,将不胜感激。

Any info would be greatly appreciated.

推荐答案

的LINQ to XML是伟大的,这种东西。你也许可以在一行中实现它,如果你想。 ,只要抢子节点的名称及其各自的价值,并添加所有那些键值对作为替代属性

Linq to XML is great for this kind of stuff. You could probably achieve it in one line if you'd want to. Just grab the child node names and their respective value and add all those 'key value pairs' as attributes instead.

MSDN文档在这里:的 http://msdn.microsoft.com/en-us/library/bb387098.aspx

MSDN docs here: http://msdn.microsoft.com/en-us/library/bb387098.aspx

这篇关于转换XML节点到使用C#属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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