c# - 在 C# 中用 ""替换新行

标签 c# xml replace newline

我想转换这个:

  <translation>
      1 Sənədlər
    </translation>

<translation>1 Sənədlər</translation>在 XML 中使用 C#。

请帮帮我。只有翻译标签。
我试过这个:

XDocument xdoc = XDocument.Load(path);
        xdoc.Save("path, SaveOptions.DisableFormatting);

但它不会删除 <translation> 之间的新行标签。

最佳答案

您所拥有的应该可以工作。您可以通过将 XDocument 转储到字符串变量来进行验证,以确认 SaveOptions 是否正在删除格式。

例如:我尝试了以下内容,但内容没有任何格式,包括换行符和空格。

        XDocument xmlDoc = new XDocument(new XElement("Team", new XElement("Developer", "Sam")));
        var content = xmlDoc.ToString(SaveOptions.DisableFormatting);

关于c# - 在 C# 中用 ""替换新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38655954/

相关文章:

c# - 列表框更新#2

file - Windows批处理覆盖文件夹和子文件夹中的现有文件

java - 如何用不同的字符串替换字符串中的特定字符?

c# - 在 C# 中从 .dot 文件创建图像

c# - C# SSH .Net 库中的 Sudo 命令

c# - String 泛型参数被视为值类型还是引用类型?

java - Android fragment - 编辑另一个 fragment 的文本

android - 图片高度太高

java - 简单的 : Element 'id' is already used

python - 重命名内置的 python 方法,如 replace()