简体   繁体   English

是否可以使用System.Configuration读取XML

[英]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.

相关问题 尽管使用System.Configuration仍无法识别ConfigurationManager - ConfigurationManager unrecognized despite using System.Configuration 使用System.Configuration验证器验证double - Validation of double using System.Configuration validator 系统.配置配置管理器 - System.Configuration Configuration Manager 如何在不使用System.Configuration的情况下以编程方式反序列化xml文件 - How To Deserialize xml File programically without System.Configuration 使用Moles覆盖System.Configuration,而不是单元测试 - Using Moles to override to System.Configuration, not as a Unit Test 如果没有本地app.config,是否可以使用System.Configuration? 以及如何处理(如果可能)? - Is it possible to use System.Configuration, if there is no local app.config? And how to, if it is possible? 定制安装程序类中的System.Configuration - System.Configuration in a custom installer class 与XMLSerializer相比,System.Configuration有什么好处? - What are the benefits of System.Configuration over XMLSerializer? 命名空间 System.Configuration 中不存在 configurationManager - configurationManager does not exist in the namespace System.Configuration 线程安全使用System.Configuration - Thread safe usage of System.Configuration
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM