简体   繁体   English

如何将XElement转换为XDocument

[英]How to convert XElement to XDocument

How can I convert XElement into XDocument? 如何将XElement转换为XDocument? Is there some built-in method for this? 有没有内置的方法呢? The only way I can think of is without new XDocument(xelement.ToString()) which will result in creating big strings and then parsing them, thus reducing the performance. 我能想到的唯一方法是没有new XDocument(xelement.ToString()) ,这将导致创建大字符串然后解析它们,从而降低性能。

只需将XElement传递给XDocument的构造函数:

var xdoc = new XDocument(new XElement("a", "b"));

我在这方面取得了很大的成功:

var xDoc = XDocument.Load(xml.CreateReader());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM