0

以下に、アプリケーションの初期化文字列の一部を示します。

<Controls>
  <HtmlElement name="lnkLogIn" type="HtmlElement">
    <AttributeMatchPath matchtype="equals">
      <href>JavaScript:void(0)</href>
      <id>s_swepi_22</id>
    </AttributeMatchPath>
  </HtmlElement>
  <InputElement name="tbPassword" type="InputElement">
    <AttributeMatchPath matchtype="equals">
      <id>s_swepi_2</id>
    </AttributeMatchPath>
  </InputElement>
  <InputElement name="tbUserID" type="InputElement">
    <AttributeMatchPath matchtype="equals">
      <id>s_swepi_1</id>
    </AttributeMatchPath>
  </InputElement>
</Controls>

コード ビハインドで実行したいのは、各コントロールの Inputelement 名と ID をキーと値のペアとして取得し、キーと値のペア情報を抽出できるディクショナリ オブジェクトなどを返す関数です。

これは基本的に、ID 値のハードコーディングを削除するために行われています....初期文字列から elementname と id を取得し、それらをキーと値のペアとして保存する一般的なソリューションは本当に素晴らしいでしょう....事前に感謝します:)

PS: C# を使用して.....

4

1 に答える 1

0

わかりました...完了.... :)

これが私がしたことです:system.xml.linq機能を使用しました:

作業コードは次のとおりです。

using System.Linq;
using System.Xml.Linq;

static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    public static void Main ( )
    {
        var xDoc = XElement.Load ( "ApplicationInit.xml" );
        var appSettingsDictionary = (xDoc.Descendants("InputElement")
            .Select ( item => new 
                             { 
                                 Key = item.Attribute("name").Value,
                                 Value = item.Descendants("id").First().Value 
                             }
                    )
                ).ToDictionary ( item => item.Key, item => item.Value );
    }
}

}

于 2012-07-12T13:41:00.843 に答える