我想創建一個使用字符串數據(這是一個XML)的XML文件。但主要問題是我創建的xml格式不正確。我已經使用XmlWriterSettings來格式化XML,但它似乎並沒有工作。任何人都可以告訴我這段代碼有什麼問題。XMl的縮進無法按預期工作!
string unformattedXml = @"<datas><data1>sampledata1</data1><datas>";
XmlWriterSettings xmlSettingsWithIndentation = new XmlWriterSettings { Indent = true};
using (XmlWriter writer = XmlWriter.Create(Console.Out, xmlSettingsWithIndentation))
{
writer.WriteRaw(unformattedXml);
}
其實當我加載此字符串一個XmlDocument,然後將其保存爲一個文件,這是formatted.I只是想知道爲什麼它不與XmlWriter的工作。
您的幫助將不勝感激。
謝謝 Alex。
我認爲,'縮進= TRUE;不適用於WriteRaw – Andrey 2011-03-29 07:54:10