如何创建在C#中的XDocument缩进XML字符串? [英] How do you create an indented XML string from an XDocument in c#?

查看:195
本文介绍了如何创建在C#中的XDocument缩进XML字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个XDocument对象和ToString()方法返回XML没有任何缩进。如何创建从这个包含缩进的XML字符串



编辑:?我问如何在内存中的字符串创建,而不是写了一个文件



编辑:看来我无意中问了一个有趣的问题这里...的ToString()不会返回缩进XML


解决方案

 的XDocument DOC = XDocument.Parse(的xmlString); 
串缩进= doc.ToString();


I have an XDocument object and the ToString() method returns XML without any indentation. How do I create a string from this containing indented XML?

edit: I'm asking how to create an in memory string rather than writing out to a file.

edit: Looks like I accidentally asked a trick question here... ToString() does return indented XML.

解决方案

XDocument doc = XDocument.Parse(xmlString);
string indented = doc.ToString();

这篇关于如何创建在C#中的XDocument缩进XML字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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