2013-05-08 20 views
0

在我們當前的代碼中,我們指出配置文件的路徑,並使用「ExeConfigurationFileMap」生成配置對象:如何生成XML字符串配置對象在C#

var fileMap = new ExeConfigurationFileMap(); 
fileMap.ExeConfigFilename = GetAppSettingWithPathByName(key); //File path 
var config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None); 

現在,我們改變策略。我已經將配置文件的內容讀入一個字符串對象,我該如何使用字符串對象來生成配置對象?

感謝

+0

你想將XML轉換爲對象 – gasroot 2013-05-08 08:07:29

回答

0

編輯:

只需使用

XDocument doc = XDocument.Load(path); 
var yourtext = doc.ToString(); 

或多個簡單

File.ReadAllLines(path); 
+0

對不起,我不知道understand.I已經將xml文件的內容讀入字符串對象中,並且我必須使用這個xml字符串 – zxi 2013-05-08 08:22:48

+0

答案已編輯 – Venson 2013-05-08 08:32:01

相關問題