2012-01-03 5 views
1

のコレクションを取得するのConfigurationManagerを使用する方法を私持っている私のApp.configファイルに次の私は、次のように私は「サービス」のセクションを取得することができます知っているわからない要素

<?xml version="1.0"?> 
<configuration> 

    <appSettings> 
    </appSettings> 

    <services> 
    <service Site="AAA1.1" Release="QA" Connection="..." Monitor="True"/> 
    <service Site="AAB1.2" Release="QA" Connection="..." Monitor="True"/> 
    <service Site="AAC1.2" Release="QA" Connection="..." Monitor="True"/> 
    <service Site="AAD3.1" Release="QA" Connection="..." Monitor="True"/> 
    <service Site="AAE3.2" Release="QA" Connection="..." Monitor="True"/> 
    <service Site="AAF5.1" Release="QA" Connection="..." Monitor="True"/> 
    <service Site="AAG5.2" Release="QA" Connection="..." Monitor="True"/> 
    </services> 

    <startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> 
    </startup> 

</configuration> 

var section = configuration.GetSection("services"); 

どのようにすればよいかわからないのは、私がセクションを持っていれば、7つの 'サービス'要素の子コレクションを取得することです。

答えて

2

それはあなたが使用しているクラスを知ってはいけないなどcreate your own Custom Configuration Sectionに、これは、あなたが強く、あなたのコレクションを入力することを可能にするパラメータのため設定されたデフォルト値と重複したエントリのようなものを扱う

-1

議論の余地がベストプラクティスですが、XmlTextReaderは(HTTP ://msdn.microsoft.com/en-us/library/system.xml.xmltextreader.aspx)は、必要なものすべてを備えています。

良いチュートリアルはこちらですhttp://www.dotnetperls.com/xmltextreader

関連する問題