本文介绍了如何添加一个现有的XML字符串转换成的XElement的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何添加一个现有的XML字符串转换成的XElement?
How to add an existing Xml string into a XElement?
这code
var doc = new XDocument(
new XElement("results", "<result>...</result>")
);
当然,产生这种
of course produces this
<results><result></result></results>
但我需要这个
but I need this
<results><result>...</result></results>
任何想法?
推荐答案
这应该工作:
var xmlString = "<result>sometext</result>";
var xDoc = new XDocument(new XElement("results", XElement.Parse(xmlString)));
这篇关于如何添加一个现有的XML字符串转换成的XElement的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!