2

tipSMS xmlの属性でSMSセクションブロックを選択したい。現在: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>
4

1 に答える 1

0

おそらくずいぶん先に進んでいると思いますが、最近ここで入手できる xml XElement の XPath ルックアップを作成しました: https://github.com/ChuckSavage/XmlLib/ jsobo のコメントを使用して必要な情報を取得したい場合。

次のように使用します。

XElement root = XElement.Load(file);
XElement sms = root.XPathElement("//Sms[@tip={0}]", "VF"); // or "//Sms[@tip='VF']"

string.Format() 構文で使用することにより、DateTime チェックなどを行いたい場合は、型を XPath にも渡します"//Sms[@tip='" + variable + "']"。XPathElement はXPath().FirstOrDefault()、単一の要素を返すだけです。

于 2012-06-04T22:57:39.553 に答える