對不起,如果標題混亂,這是我想要實現的。我正在創建並傳遞給方法如何在XmlWriter上爲特定元素節點設置縮進屬性
public static void foo(XmlWriter xw)
{
xw.WriteStartElement("root");
}
此時的XmlWriter實例化一個XmlWriter對象,以及XML聲明已經寫。現在,編寫根元素後,我需要將XmlWriter上的Indent屬性設置爲true(當創建XmlWriter時,它被設置爲false)。像這樣的東西
public static void foo(XmlWriter xw)
{
xw.WriteStartElement("root");
// xw.Settings.Indent = true; - I know this won't work
// continue writing elements...
}
無法找到如何設置縮進在這一點。有任何想法嗎 ?
感謝您的建議,我寧願堅持使用XmlWriter,因爲改變它到XmlTextWriter將需要我改變這整個模塊。所有的組件都依賴於XmlWriter,所以我不能輕易做出改變。還有其他建議嗎? – Michael
我做了一些更多的研究。一旦XmlWriter無法更改設置屬性。 http://msdn.microsoft.com/en-us/library/system.xml.xmlwriter.settings.aspx – mosca125
似乎你需要重構模塊,如果你想縮進或更新XmlWriter的創建地點和通過XmlWriterSettings – mosca125