日期:2014-05-20 浏览次数:20916 次
<?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <!--测试环境数据--> <add key="Appkey" value="12337722" /> <add key="Appsecret" value="sandboxda3e9856fbb65050b45a5efef" /> <add key="Url" value="http://gw.api.tbsandbox.com/router/rest" /> <add key="SessionKey" value="" /> <!--正式环境数据--> <add key="OnLineAppkey" value="12337722" /> <add key="OnLineAppsecret" value="0ed1394da3e9856fbb65050b45a5efef" /> <add key="OnLineUrl" value="http://gw.api.taobao.com/router/rest" /> <add key="OnLineSessionKey" value="" /> </appSettings> </configuration>
public class ConfigModel { public string TandBoxAppkey { get; set; } public string TandBoxAppsecret { get; set; } public string TandBoxUrl{get;set;} public string TandBoxSessionKey { get; set; } public string OnLineAppkey { get; set; } public string OnLineAppsecret { get; set; } public string OnLineUrl { get; set; } public string OnLineSessionKey { get; set; } }
void Main() { string xml=@"<?xml version=""1.0"" encoding=""utf-8"" ?> <configuration> <appSettings> <!--测试环境数据--> <add key=""Appkey"" value=""12337722"" /> <add key=""Appsecret"" value=""sandboxda3e9856fbb65050b45a5efef"" /> <add key=""Url"" value=""http://gw.api.tbsandbox.com/router/rest"" /> <add key=""SessionKey"" value="""" /> <!--正式环境数据--> <add key=""OnLineAppkey"" value=""12337722"" /> <add key=""OnLineAppsecret"" value=""0ed1394da3e9856fbb65050b45a5efef"" /> <add key=""OnLineUrl"" value=""http://gw.api.taobao.com/router/rest"" /> <add key=""OnLineSessionKey"" value="""" /> </appSettings> </configuration>"; var data=XElement.Parse(xml).Descendants("add"); ConfigModel cg=new ConfigModel { TandBoxAppkey=data.FirstOrDefault(d=>d.Attribute("key").Value=="Appkey").Attribute("value").Value, TandBoxAppsecret=data.FirstOrDefault(d=>d.Attribute("key").Value=="Appsecret").Attribute("value").Value, TandBoxUrl=data.FirstOrDefault(d=>d.Attribute("key").Value=="Url").Attribute("value").Value, TandBoxSessionKey=data.FirstOrDefault(d=>d.Attribute("key").Value=="SessionKey").Attribute("value").Value, OnLineAppkey=data.FirstOrDefault(d=>d.Attribute("key").Value=="OnLineAppkey").Attribute("value").Value, OnLineAppsecret=data.FirstOrDefault(d=>d.Attribute("key").Value=="OnLineAppsecret").Attribute("value").Value, OnLineUrl=data.FirstOrDefault(d=>d.Attribute("key").Value=="OnLineUrl").Attribute("value").Value, OnLineSessionKey=data.FirstOrDefault(d=>d.Attribute("key").Value=="OnLineSessionKey").Attribute("value").Value }; Console.WriteLine(cg); } public class ConfigModel { public string TandBoxAppkey { get; set; } public string TandBoxAppsecret { get; set; } public string TandBoxUrl{get;set;} public string TandBoxSessionKey { get; set; } public string OnLineAppkey { get; set; } public string OnLineAppsecret { get; set; } public string OnLineUrl { get; set; } public string OnLineSessionKey { get; set; } }