将XDocument转换为不添加/r/n的字符串



你好,我正试图找到一种将XDocument转换为字符串的方法,以便通过ajax调用将其发回。

所以我有一个XDocument如下

var xml = new XDocument(
new XElement("Contract",
new XAttribute("version", "1.0"),
new XElement("child", "Hello World!")));

我可以通过以下将其转换为字符串

string i = xml.Document.ToString();

但是通过这样做,我的xml文档出现了错误,因为添加了很多r/n和很多"/"。有没有一种方法可以在不添加这些值的情况下将XDocument转换为字符串?

我得到的字符串

"<Contract version="1.0">rn  <child>Hello World!</child>rn</Contract>"

这应该可以做到:

string i = xml.Document.ToString(SaveOptions.DisableFormatting);

最新更新