使用C#将XML节点转换为属性我正在尝试将文本节点转换为属性(使用C#),所以它看起来像这样:任何信息将不胜感激。LinqtoXML非常适合这类东西。如果你愿意,你可以一行完成。只需获取子节点名称及其各自的值,并将所有这些“键值对”添加为属性即可。MSDN文档:http://msdn.microsoft.com/en-us/library/bb387098.aspx正如seldon所建议的,LINQtoXML更适合此类任务。但这里是如何使用XmlDocument来完成的。并不声称这是万无一失的(尚未测试),但它确实适用于您的样本。以上就是C#学习教程:使用C#将XML节点转换为属性分享全部内容。如果对你有用,需要进一步了解C#学习教程,希望大家多多关注—XmlDocumentinput=...//Createoutputdocument.XmlDocumentoutput=newXmlDocument();//创建输出根元素:...varroot=output.CreateElement(input.DocumentElement.Name);//将属性附加到输出根元素//从输入的元素document.foreach(varchildininput.DocumentElement.ChildNodes.OfType()){varattribute=output.CreateAttribute(child.Name);//到attribute.Value=child.InnerXml;//to="你"root.Attributes.Append(attribute);//}//生成输出的根元素document.output.AppendChild(root);如需转载请注明出处:
