[英]Is it possible to read XML using System.Configuration
Currently i am using XElement
for parsing XML
and read each node which required by application. 目前,我正在使用
XElement
解析XML
并读取应用程序所需的每个节点。
Now i want to read XML
by using System.Configuration
.Is this possible, what i think.My config.xml have not any configuration section
.It just plain XML
. 现在我想使用
System.Configuration
读取XML
。我认为这是可能的。我的config.xml没有任何configuration section
它只是纯XML
。
<?xml version="1.0" encoding="utf-8" ?>
<ConfigSetting>
<!--The reports name which needs to be changed in to tethystrader db created on the fly.-->
<ReportsName value="Tethys_Price_report,Tethys_Liquidity_report,Tethys_Liquidity_report_option"/>
<MasterConnectionSetting connectionString="Data Source=NDI-LAP-262\SQL2008R2;Initial Catalog=master;UID=sa;pwd=Brick@123;" />
<!--Create db for check Liquidityreport/execta daily scenario-->
<Setup scenario="LIQ" outputFilePath="..\..\..\..\..\..\Branch_3.2.5">
<ServerSetting>
<ConnectionSetting component="RGTestToolDB" connectionString="server=NDI-LAP-262\SQL2008R2;integrated security=SSPI;uid=sa;pwd=Brick@123;database=~;Connection Timeout=1;" />
<ConnectionSetting component="TethysTrader" connectionString="server=NDI-LAP-262\SQL2008R2;integrated security=SSPI;uid=sa;pwd=Brick@123;database=~;Connection Timeout=1;" />
<ConnectionSetting component="TethysCommonDB" connectionString="server=NDI-LAP-262\SQL2008R2;integrated security=SSPI;uid=sa;pwd=Brick@123;database=~;Connection Timeout=1;" />
</ServerSetting>
<DB component="TethysTrader">
<cabfile path="Output\TethysTrader.cab" />
<cabfile path="Output\TethysTrader-RG.cab" />
<object tablename="order_msgs" file="TethysTraderDB\order_msgs.csv" />
<object tablename="order_msgs_incoming" file="TethysTraderDB\order_msgs_incoming.csv" />
</DB>
</Setup>
</ConfigSetting>
Please suggest. 请提出建议。
Because this is not a valid configuration file (it contains no <configurationSettings>
element, nor a <configSections>
element to describe unknown sections) you can't read it through System.Configuration
. 由于这不是有效的配置文件(它不包含
<configurationSettings>
元素,也不包含用于描述未知部分的<configSections>
元素),因此无法通过System.Configuration
读取它。 What you want is better achieved by either moving all of this data into a custom configuration section (see the MSDN for more information on how to do that -- the page talks about ASP.NET, but it works outside ASP.NET just as well) or keep this data in a separate file that you parse with XElement
(there's nothing wrong with that solution). 通过将所有这些数据移动到自定义配置部分中,可以更好地实现所需的信息(有关此操作的更多信息,请参见MSDN ,该页面讨论了ASP.NET,但它也可以在ASP.NET之外运行),或将此数据保存在您使用
XElement
解析的单独文件中(该解决方案没有问题)。
The benefit of using a custom configuration section is that you keep a single app.config
, which is easier to maintain and deploy. 使用自定义配置部分的好处是您保留了一个
app.config
,它更易于维护和部署。 You can also benefit from the built-in advantages of .NET configuration files, like the ability to have a per-machine and per-user file to supply defaults. 您还可以受益于.NET配置文件的内置优势,例如具有按机器和按用户提供默认文件的功能。 The drawback is that you need to write separate code for it (and understanding how this works is not completely trivial).
缺点是您需要为此编写单独的代码(并且了解其工作原理并不完全是琐碎的)。
Keeping the data in a separate file that you parse yourself is easier to understand, but you don't get the support for machine- or user-specific files, and you have to deploy and maintain two files if you need some settings in app.config
anyway. 将数据保存在您自己解析的单独文件中更容易理解,但是您没有获得针对计算机或用户特定文件的支持,并且如果需要在
app.config
某些设置,则必须部署和维护两个文件app.config
无论如何app.config
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.