简体   繁体   English

在 XML 中使用制表符而不是空格缩进

[英]Indent with tabs instead of spaces in XML

Okay so I have some code which is supposed to change a value in a configuration file.好的,所以我有一些代码应该更改配置文件中的值。

        string xmlFile = "KeePass.config.xml";
        System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
        XmlWriterSettings settings = new XmlWriterSettings();
        settings.IndentChars = "\t";
        settings.Indent = true;
        xmlDoc.Load(xmlFile);
        xmlDoc.SelectSingleNode("Configuration/Application/LastUsedFile").InnerText = fileName;
        xmlDoc.Save(xmlFile);

The problem with this is that it indents the XML file with spaces instead of tabs and the program which reads the configuration file needs to see the XML with tab indents.这样做的问题是它使用空格而不是制表符缩进 XML 文件,并且读取配置文件的程序需要查看带有制表符缩进的 XML。 Any help would be appreciated.任何帮助,将不胜感激。

你有没有尝试过

xmlDoc.PreserveWhitespace = true;

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

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