[英]How to the replace node names with new name and keep the attributes using C# and Linq to XML?
I need to change 我需要改变
<Test Language="English" Id="0" />
to 至
<Exam Language="English" Id="0" />
How to the replace node names with new name and keep the attributes ? 如何用新名称替换节点名称并保留属性?
You can use Name
property 您可以使用
Name
属性
var xdoc = XDocument.Load("input.xml");
var nodes=xdoc.Descendants("Test").ToList();//Get all "Test" node
nodes.ForEach(d => d.Name = "Exam "); // Set name to 'Exam'
xdoc.Save("output.xml");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.