【发布时间】:2012-03-28 12:16:13
【问题描述】:
我想根据短信xml的tip属性选择短信段块。
目前:ConfigurationManager.GetSection("Logger/Sms") 有效,但有没有办法获得像ConfigurationManager.GetSection("Logger/Sms[@tip='VF']") 这样的部分?
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="Logger">
<section name="Sms" type="caSectionTest.LogHandler, caSectionTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</sectionGroup>
</configSections>
<Logger>
<Sms tip="Clickatell">
<icerik>Soğuk zincir uygulamasından gönderilen sms</icerik>
<telNo>9053123123123</telNo>
<api>3363050</api>
<user>pkUser</user>
<pass>passhm</pass>
</Sms>
<Sms tip="Vodafone">
<icerik>write something into sms</icerik>
<telNo>905123123123</telNo>
<originator>336123</originator>
<user>ctUser</user>
<pass>9Mdfpass</pass>
</Sms>
</Logger>
</configuration>
【问题讨论】:
-
我使用的一个技巧是抓取整个部分...然后将 xml 反序列化为一个对象。然后您可以使用该对象来获取您的配置项,而您没有弄乱那个疯狂的语法。
-
你确定这行得通吗?当我尝试从
web.config或app.config文件中获取此信息时,我收到Sections must only appear once per config file. See the help topic <location> for exceptions.错误。您能否更新问题以包含有关如何重现此问题的说明?
标签: c# xml configurationsection