【问题标题】:When using XmlWriter in C#, is there a way to have some elements written on the same line and others on their own respective lines?在 C# 中使用 XmlWriter 时,有没有办法让一些元素写在同一行,而另一些元素写在各自的行上?
【发布时间】:2019-11-27 15:11:56
【问题描述】:

我正在使用 XmlWriter 制作一个 xml 文件,并且遇到了一个问题,因为我需要一些 cmets 与其他元素位于同一行,即

<string> text </string> <!-- comment -->

但是,我还需要有一些在他们自己的线上,即

<string> text </string>

<!-- comment -->

我怀疑我不能这样做,因为缩进行的设置是在作者创建时设置的,但想知道是否有人可能有想法。

【问题讨论】:

标签: c# .net xml xmlwriter


【解决方案1】:

如果 Indent 设置为 false,那么使用

添加您自己的换行符很容易
writer.WriteRaw(Environment.NewLine);

如果 Indent 设置为 true,则编写器正在为您插入换行符,您无法逐个覆盖它们。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-09
    • 1970-01-01
    • 2020-10-09
    • 2019-12-15
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 2020-09-05
    相关资源
    最近更新 更多